Created
September 8, 2016 22:49
-
-
Save ace139/e8f3f42815805610110d76d0603fac50 to your computer and use it in GitHub Desktop.
Counting alphabets in a file
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
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