Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43345 > unrolled thread
| Started by | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
|---|---|
| First post | 2013-04-11 10:58 +0100 |
| Last post | 2013-04-11 10:58 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Can I iterate over a dictionary outside a function ? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-04-11 10:58 +0100
| 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 ? |
| Message-ID | <mailman.454.1365674357.3114.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web