Skip to content

Instantly share code, notes, and snippets.

@ace139
Created September 8, 2016 22:49
Show Gist options
  • Save ace139/e8f3f42815805610110d76d0603fac50 to your computer and use it in GitHub Desktop.
Save ace139/e8f3f42815805610110d76d0603fac50 to your computer and use it in GitHub Desktop.
Counting alphabets in a file
d = dict()
with open('lipsum.txt') as f:
for line in f:
for i in line:
if i.isalpha():
d[i.upper()] = d.get(i.upper(), 0) + 1
for key, val in sorted(d.items()):
print("%s : %d" % (key, val))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment