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


Groups > comp.lang.python > #43358

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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Neil Cerutti <neilc@norwich.edu>
Newsgroups comp.lang.python
Subject Re: Can I iterate over a dictionary outside a function ?
Date 11 Apr 2013 12:18:18 GMT
Organization Norwich University
Lines 18
Message-ID <asno0aFfh28U2@mid.individual.net> (permalink)
References <CAFqGZRH-Yxuwb=7uxvkbY+KPJPfv+1qP=fTdXufqEzYfjwUHsQ@mail.gmail.com> <mailman.462.1365681127.3114.python-list@python.org>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Trace individual.net 6pZ67WbzXf5O2breMLUnowrQEnmY0ABfbqll88MBHpocU09YIr
Cancel-Lock sha1:HXJvjWa2Sh3GAwK6OzR0NZ7qlRQ=
User-Agent slrn/0.9.9p1/mm/ao (Win32)
Xref csiph.com comp.lang.python:43358

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

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

csiph-web