This a problem in my textbook, where you create a program that makes a histogram of the emails in the text file (which they are always the second word).
handle = open("mbox-short.txt")
senders = {}
for line in handle:
if line.startswith('From'):
emails = line.split()
if len(emails) < 3: continue
email = emails[1]
senders[email] = senders.get(email , 0) + 1
bigsender = None
bigcount = None
for sender,times in senders.items():
if bigcount < times:
bigcount = times
bigsender = sender
print(bigsender, bigcount)
But when I run it produces an error which says:
TypeError: '<' not supported between instances of 'NoneType' and 'int'
Yet when I change the last condition to:
if bigcount is None or bigcount < times:
Aren't we still comparing bigcount to times, I don't get what did change?
This is text file: https://www.py4e.com/code3/mbox-short.txt