B1 – File Letter Count

Make a Python script named file_letter_count.py that prompts the user for a file path, read text from that file using the read() function, count the number of times each letter appears in that file, and output the letter count histogram. Use Gist and the Submission form to submit your code.

Here is the example output if we read in the original letter_count.py (see file below):

Enter input file path: letter_count.py

Summary
a: 34
b: 3
c: 23
d: 15
e: 72
f: 9
g: 13
h: 12
i: 43
j: 3
k: 13
l: 22
m: 11
n: 27
o: 24
p: 17
q: 3
r: 58
s: 32
t: 79
u: 11
v: 5
w: 9
x: 10
y: 13
z: 3

Histogram
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: ***
SelectionFile type iconFile nameDescriptionSizeRevisionTimeUser
ċ

Download
  1k v. 3 Aug 2, 2012, 10:45 PM Sophie Engle
Comments