Chapter 9 Dictionaries Assignment 9.4

name = raw_input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
fh=open(name)
counts =dict()
ww=list()
for line in fh:
    line=line.rstrip()
    if not line.startswith('From '):continue
    w=line.split()
    ww.append(w[1])
for w in ww:
    counts[w]=counts.get(w,0)+1


bigcount=None
bigword=None
for w,count in counts.items():
    if bigcount is None or count>bigcount:
        bigword=w
        bigcount=count
print bigword,bigcount

你可能感兴趣的:(python)