Can I iterate over a dictionary outside a function ?

Neil Cerutti neilc at norwich.edu
Thu Apr 11 08:18:18 EDT 2013


On 2013-04-11, Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:
> On 11/04/2013 10:48, inshu chauhan wrote:
>> I have a prog in which a functions returns a dict but when I
>> try to iterate over the dict using iterkeys, It shows an
>> error. I think its because only address of the dictionary is
>> returned so cannot be iterated upon.
>>
>> Please suggest some way by which it can be made possible to
>> iterate over the dictionary using  iterkeys outside the
>> function ?
>
> If you're using Python 3 iterkeys has been renamed keys.

Also, using a dict *as* an iterator results in iterating over the
keys.

-- 
Neil Cerutti



More information about the Python-list mailing list