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


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

Re: Python 3: dict & dict.keys()

Started byChristian Heimes <christian@python.org>
First post2013-07-24 23:06 +0200
Last post2013-07-24 23:06 +0200
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.


Contents

  Re: Python 3: dict & dict.keys() Christian Heimes <christian@python.org> - 2013-07-24 23:06 +0200

#51167 — Re: Python 3: dict & dict.keys()

FromChristian Heimes <christian@python.org>
Date2013-07-24 23:06 +0200
SubjectRe: Python 3: dict & dict.keys()
Message-ID<mailman.5065.1374700034.3114.python-list@python.org>
Am 24.07.2013 18:34, schrieb Chris Angelico:
> Side point: Why is iterating over a dict equivalent to .keys() rather
> than .items()? It feels odd that, with both options viable, the
> implicit version iterates over half the dict instead of all of it.
> Obviously it can't be changed now, even if .items() were the better
> choice, but I'm curious as to the reason for the decision.

Consider this:

if key in dict:
    ...

for key in dict:
   ...

It would be rather surprising if "in" as containment checks operates on
keys and "in" as iterator returns (key, value) tuples.

Christian

[toc] | [standalone]


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


csiph-web