SHARE
TWEET

Untitled

a guest May 25th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # method 1
  2. colors = ['red', 'green', 'blue', 'orange', 'purple', 'red', 'blue', 'blue']
  3.  
  4. d = {}
  5. for color in colors:
  6.     d[color] = d.get(color, 0) + 1
  7.    
  8. print(d)
  9.  
  10. # method 2
  11. from collections import Counter
  12.  
  13. colors = ['red', 'green', 'blue', 'orange', 'purple', 'red', 'blue', 'blue']
  14. dic = Counter(colors)
  15.  
  16. print(dic)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top