# Basic syntax: dict_of_counts = {item:your_list.count(item) for item in your_list} # Example usage: your_list = ["a", "b", "a", "c", "c", "a", "c"] dict_of_counts = {item:your_list.count(item) for item in your_list} print(dict_of_counts) --> {'a': 3, 'b': 1, 'c': 3}
Here is what the above code is Doing:
1. We create an empty dictionary, dict_of_counts.
2. We iterate through your_list.
3. For each item in your_list, we count how many times it appears in your_list.
4. We add the item and its count to dict_of_counts.
5. We print dict_of_counts.