Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Why doesn't this work? (iteration over non-sequence)

I have a dictionary with each key containing a list as a value. And I'm trying to go over all the items in the lists, and let's say I'm trying to print all the items as I go through, I wrote:

for item in aDict: 
    for item2 in aDict[item]: 
        print item2

This prints out the items in the list for the first value, then it gives me an error saying "iteration over non-sequence". Why is this and how should I do this?

Thanks in advance.

like image 693
Dennis Avatar asked Jan 29 '26 07:01

Dennis


1 Answers

One of your dictionary values is not a list!

like image 61
Steven Rumbalski Avatar answered Jan 30 '26 19:01

Steven Rumbalski