Advertisement
zhongnaomi

Count number of occurrences in a list of strings

Feb 6th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. from collections import Counter
  2.  
  3. colours =['white', 'white', 'green', 'purple', 'black', 'white', 'white',
  4. 'black', 'blue',     'purple', 'yellow', 'green', 'white',
  5. 'blue', 'blue', 'green', 'green', 'red', 'black', 'yellow',
  6. 'white', 'blue', 'orange', 'green', 'blue', 'green', 'white',
  7. 'red', 'yellow', 'red', 'green', 'white', 'red', 'white',
  8. 'yellow', 'orange', 'red', 'black', 'green', 'orange', 'purple',
  9. 'blue', 'red', 'red', 'blue', 'purple', 'yellow', 'yellow', 'red',
  10. 'yellow']
  11.  
  12.  
  13. print(Counter(colours))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement