Can I iterate over a dictionary outside a function ?

Alexander Blinne news at blinne.net
Thu Apr 11 17:33:42 EDT 2013


Am 11.04.2013 11:48, schrieb inshu chauhan:
> 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.

1) Show us your code in form of a minimal "working" example, "working"
means that it should show us what you expect it to do but at the same
time shows the behaviour you complain about.

2) Show us your actual error message!

> I think its
> because only address of the dictionary is returned so cannot be iterated
> upon. 

Python does not use addresses, it uses references. And as long as you
have a valid reference to a dict assigned to some name in some namespace
you should be able to iterate over its keys using some_dict.iterkeys().




More information about the Python-list mailing list