Advertisement
zhongnaomi

the most popular item in a list

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