Guest User

Untitled

a guest
Dec 14th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. # Collections.Counter lets you find the most common elements in an iterable:
  2.  
  3. >>> import collections
  4. >>> c = collections.Counter('helloworld')
  5.  
  6. >>> c
  7. Counter({'l': 3, 'o': 2, 'e': 1, 'd': 1, 'h': 1, 'r': 1, 'w': 1})
  8.  
  9. >>> c.most_common(2)
  10. [('l', 3), ('o', 2)]
  11.  
  12. >>> c.most_common(3)
  13. [('l', 3), ('o', 2), ('e', 1)]
Add Comment
Please, Sign In to add comment