Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import defaultdict
- colors = ['red', 'green', 'blue', 'orange', 'purple', 'red', 'blue', 'blue']
- d = defaultdict(int)
- for color in colors:
- d[color] += 1
- print(d)
- d = defaultdict(list)
- for color in colors:
- key = len(color)
- d[key].append(color)
- print(d)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement