Created
May 30, 2012 11:08
-
-
Save jmora/2835547 to your computer and use it in GitHub Desktop.
Short script to count how many times words appear on a file, you may need to change the re
This file contains hidden or 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
#!/usr/bin/python3 | |
import re, sys | |
if __name__ == "__main__": | |
c = {} | |
with open(sys.argv[1], "r") as f: | |
for l in f: | |
for e in re.findall("\w+", l): | |
c[e] = c.get(e, 0) + 1 | |
for e in sorted(c.items(), key=lambda i:i[1], reverse=True): | |
print("%s %d"%e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment