Currently working on this for Coursera's Python For everybody class. This is ex 9.4. For some reason the emcount is double what it is supposed to be when ran. The problem seems to start early on since line has double the amount it should. Does anyone have an idea of where I went wrong? Thanks!
name = input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
lst = list()
#emcount = dict()
for line in handle:
if not line.startswith("From"): continue
line=line.split()
print(line)
lst.append(line[1])#adding each email occurrence to lst
# print(lst)
emcount = dict()
for word in lst:
emcount[word] = emcount.get(word,0)+1
# print(emcount)
bigcount = 0#empty at beginning
bigword = None
for word,count in emcount.items():
#items give you acopy of each key value pair, word is the key
if bigcount> count:
bigcount = bigcount
bigword = bigword
print(bigword, bigcount)
else:
bigcount = count
bigword = word
`