"'int' object is not iterable" iterating over a dict

Alex_Gaynor alex.gaynor at gmail.com
Sun Oct 5 20:15:13 EDT 2008


On Oct 5, 8:11 pm, mmiikkee13 <mmiikke... at gmail.com> wrote:
> >>> a_list = range(37)
> >>> list_as_dict = dict(zip(range(len(a_list)), [str(i) for i in a_list]))
> >>> for k, v in list_as_dict:
>
> ...     print k, v
> ...
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: 'int' object is not iterable
>
> What 'int' object is this referring to? I'm iterating over a dict, not
> an int.

It thinks you are trying to unpack the first item, you mean to be
doing for k, v in list_as_dict.iteritems()



More information about the Python-list mailing list