Last active
June 19, 2017 17:55
-
-
Save barce/2f688adb919adaebe31784180858f9c9 to your computer and use it in GitHub Desktop.
collections in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
c = collections.Counter('helloworld') | |
print(c) | |
# Counter({'l': 3, 'o': 2, 'e': 1, 'd': 1, 'h': 1, 'r': 1, 'w': 1}) | |
print(c.most_common(3)) | |
# [('l', 3), ('o', 2), ('e', 1)] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment