Python Forum

Full Version: ValueError
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all, new to Python and programming and having an issue here that I can't figure out. I'm getting a value error from this code. I'm trying to print out their names neatly and their favourite numbers, very simple.

Any help appreciated, thanks!

favourite_numbers = {
	'mara': ['0', '51'],
	'jared': ['1', '73'],
	'stranger1': ['2', '61'],
	'stranger2': ['3', '9053'],
	'stranger3': ['4', '7'],
	}
#looping through dictionary favourite_numbers	
for name, number in favourite_numbers:
	print(name.title() + "'s favourite numbers are: ")
	for nums in number:
		print("\t" + nums)
If you want to iterate of the keys and values of the dictionary at the same time, you need to use the items method:

for name, number in favourite_numbers.items():
Default iteration over a dictionary just returns the keys.
Gah!! I can't believe I didn't notice it! Haha. Thanks!! All my other code has the items and I was using it as a reference because it had worked but I somehow missed the .items.