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


Groups > comp.lang.python > #43403

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

Date 2013-04-11 23:33 +0200
From Alexander Blinne <news@blinne.net>
Newsgroups comp.lang.python
Subject Re: Can I iterate over a dictionary outside a function ?
References <mailman.452.1365673689.3114.python-list@python.org>
Message-ID <51672c36$0$6623$9b4e6d93@newsspool2.arcor-online.net> (permalink)
Organization Arcor

Show all headers | View raw


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().

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


Thread

Can I iterate over a dictionary outside a function ? inshu chauhan <insideshoes@gmail.com> - 2013-04-11 15:18 +0530
  Re: Can I iterate over a dictionary outside a function ? Alexander Blinne <news@blinne.net> - 2013-04-11 23:33 +0200

csiph-web