我正在尝试运行以下代码行

时间:2018-07-13 15:17:59

标签: python-3.x

有人可以帮助我解决此代码的问题吗?

fname=input("Enter the name of the file:")
fhandle=open(fname)
word=list()
for line in fhandle:  #All lines starting with "From " are split into list of words
    if not line.startswith("From "):
        continue
        words=line.split()
        word=words[1]            #Second word is obtained
 #Dictionary to count occurence
 counts=dict()
 for name in word:
    counts[name] = counts.get(name,0)+1
     print(counts[name],name)
     print(counts)

#Deciding the maximum occurence of name
maxcount=None
maxword=None
for word,count in counts.items():
    if maxcount is None or count > maxcount:  #if we are ont first word or if 
 the current count is greater than previous maximum count
        maxcount=count
        maxword=word
 print(maxword,maxcount)

我期望的输出是打印     输出:     cwen@iupui.edu 5 但是我最终得到None None作为输出。有人可以帮我造成过去4个小时的困扰吗?

0 个答案:

没有答案