Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43354 > unrolled thread

Re: Can I iterate over a dictionary outside a function ?

Started byMark Lawrence <breamoreboy@yahoo.co.uk>
First post2013-04-11 12:53 +0100
Last post2013-04-11 12:18 +0000
Articles 2 — 2 participants

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.


Contents

  Re: Can I iterate over a dictionary outside a function ? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-04-11 12:53 +0100
    Re: Can I iterate over a dictionary outside a function ? Neil Cerutti <neilc@norwich.edu> - 2013-04-11 12:18 +0000

#43354 — Re: Can I iterate over a dictionary outside a function ?

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-04-11 12:53 +0100
SubjectRe: Can I iterate over a dictionary outside a function ?
Message-ID<mailman.462.1365681127.3114.python-list@python.org>
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.

-- 
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.

Mark Lawrence

[toc] | [next] | [standalone]


#43358

FromNeil Cerutti <neilc@norwich.edu>
Date2013-04-11 12:18 +0000
Message-ID<asno0aFfh28U2@mid.individual.net>
In reply to#43354
On 2013-04-11, Mark Lawrence <breamoreboy@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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web