Advertisement
Guest User

Untitled

a guest
May 25th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. from collections import defaultdict
  2.  
  3. colors = ['red', 'green', 'blue', 'orange', 'purple', 'red', 'blue', 'blue']
  4. d = defaultdict(int)
  5.  
  6. for color in colors:
  7. d[color] += 1
  8.  
  9. print(d)
  10.  
  11. d = defaultdict(list)
  12.  
  13. for color in colors:
  14. key = len(color)
  15. d[key].append(color)
  16.  
  17. print(d)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement