Skip to content

Instantly share code, notes, and snippets.

@aladinoster
Created August 9, 2021 05:27
Show Gist options
  • Save aladinoster/ba5dc94854e309e17e0983907b9b13e4 to your computer and use it in GitHub Desktop.
Save aladinoster/ba5dc94854e309e17e0983907b9b13e4 to your computer and use it in GitHub Desktop.
Python: Simple histogram from text or iterables
from collections import Counter
if __name__ == "__main__":
txt = "This is a vast world you can't traverse world in a day"
counts = Counter(txt.split())
print("Here is a sample of counts: ", counts)
print("The most common elements are: ", counts.most_common(2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment