Skip to content

Instantly share code, notes, and snippets.

@jackdalton
Created May 25, 2016 18:09
Show Gist options
  • Save jackdalton/fab46013b3ce69fcfb41481182ea8a80 to your computer and use it in GitHub Desktop.
Save jackdalton/fab46013b3ce69fcfb41481182ea8a80 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# coding=utf-8
from __future__ import division
import sys
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
def letter_makeup(file_name):
file_contents = ""
with file(file_name) as f: file_contents = f.read().lower()
occurences = []
for i in alphabet:
occurences.append(file_contents.count(i))
total = sum(occurences)
occurences_p = []
for i in occurences:
occurences_p.append((i / total) * 100.0)
str_out = """
a %d%%
b %d%%
c %d%%
d %d%%
e %d%%
f %d%%
g %d%%
h %d%%
i %d%%
j %d%%
k %d%%
l %d%%
m %d%%
n %d%%
o %d%%
p %d%%
q %d%%
r %d%%
s %d%%
t %d%%
u %d%%
v %d%%
w %d%%
x %d%%
y %d%%
z %d%%
""" % tuple(occurences_p)
return str_out
if len(sys.argv) < 2:
print("At least one argument expected.")
else:
for i in sys.argv[1:]:
print("%s:\n" % (i))
print(letter_makeup(i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment