csev/py4e

PY4E data structure EX:9.4

MennaAssal opened this issue · 1 comments

I tried a lot to do this exercise ,but I have errors.
Could you please help me understand what is the problem?

name = input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
counts=dict()
for line in handle:
line = line.rstrip()
if line == "" : continue
words = line.split()
for word in words:
if words[1] != "From" : continue
# if words == " ":continue
counts[word]=counts.get(word,0)+1
bigcounts=None
bigwords=None
for word,count in counts.item():
if bigcounts is None or count>bigcounts:
bigwords=word
bigcounts=count
print(bigwords,bigcounts)

`

9.4 is an assignment so you can't get help here. Please use the discussions for the MOOC (Coursera, edX) that you are subscribed to.