真是难想,前期进了坑,搞不懂视频中的所谓的优势在哪,所以一直在坑里爬不出来,后来用了上期的词组划分才解决了这个问题
题目来源:coursera 密歇根大学 Python数据结构 Assignment 9.4
name = raw_input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
counts = dict()
for line in handle:
line = line.strip()
word = line.split()
if len(word):
if word[0] == 'From':
counts[word[1]] = counts.get(word[1],0)+1
bigcount = 0
bigword = 0
for word,count in counts.items():
if count > bigcount :
bigcount = count
bigword = word
print bigword,bigcount