Hey there, I’m currently on Dictionaries and Loops in Python. At 7:11 of the video we are given a script “Using Two Nested Loops”
I want to understand this but I’m given an error when I try the code myself.
TypeError: ‘>’ not supported between instances of ‘int’ and ‘dict’
#Using_Two_nested_Loops
name = input('Enter file:')
handle = open(name)
counts = dict("")
for line in handle:
words = line.split()
for word in words:
counts[word] = counts.get(word,0) + 1
bigcount = None
bigword = None
for word,count in counts.items():
if bigcount is None or count > bigcount:
bigword = words
bigcount = counts
print(bigword, bigcount)
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.