Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43345
| References | <CAFqGZRH-Yxuwb=7uxvkbY+KPJPfv+1qP=fTdXufqEzYfjwUHsQ@mail.gmail.com> |
|---|---|
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
| Date | 2013-04-11 10:58 +0100 |
| Subject | Re: Can I iterate over a dictionary outside a function ? |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.454.1365674357.3114.python-list@python.org> (permalink) |
On 11 April 2013 10:48, inshu chauhan <insideshoes@gmail.com> 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 ?
You would probably get a more helpful answer if you showed the code
that is giving you a problem. See here:
http://sscce.org/
Your question makes no sense to me. It is perfectly possible to
iterate over a dict returned from a function:
>>> def function():
... d = {'asd':123, 'qwe': 456}
... return d
...
>>> a = function()
>>> a
{'qwe': 456, 'asd': 123}
>>> for x in a.iterkeys():
... print(x)
...
qwe
asd
Oscar
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Can I iterate over a dictionary outside a function ? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-11 10:58 +0100
csiph-web