1MyList = ["a", "b", "a", "c", "c", "a", "c"]
2
3return my_dict = {i:MyList.count(i) for i in MyList}
4# returns :
5{'a': 3, 'c': 3, 'b': 1}
6 # OR
7from collections import Counter
8return my_dict = dict(Counter(MyList))
9# returns :
10{'a': 3, 'c': 3, 'b': 1}
11# the both returns the same so it's up to you to choose the one you prefere ;)
1# Basic syntax:
2dict_of_counts = {item:your_list.count(item) for item in your_list}
3
4# Example usage:
5your_list = ["a", "b", "a", "c", "c", "a", "c"]
6dict_of_counts = {item:your_list.count(item) for item in your_list}
7print(dict_of_counts)
8--> {'a': 3, 'b': 1, 'c': 3}
1a=["a","a","a","b","a","b","c","c","c","d","d",]
2dic={}
3for i in a:
4 dic={i:a.count(i)}
5print(dic)
6
7#return b={i:a.count(i) for i in a}
8