Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # method 1
- colors = ['red', 'green', 'blue', 'orange', 'purple', 'red', 'blue', 'blue']
- d = {}
- for color in colors:
- d[color] = d.get(color, 0) + 1
- print(d)
- # method 2
- from collections import Counter
- colors = ['red', 'green', 'blue', 'orange', 'purple', 'red', 'blue', 'blue']
- dic = Counter(colors)
- print(dic)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement