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


Groups > comp.lang.python > #51167

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

From Christian Heimes <christian@python.org>
Subject Re: Python 3: dict & dict.keys()
Date 2013-07-24 23:06 +0200
References <51EF2AD8.3080105@stoneleaf.us> <ksnrr9$k4t$1@ger.gmane.org> <CAHVvXxQGCFJe7ud+mwh4zhnq5F7xvHJX1pCtGCjMaFtjBwY=iQ@mail.gmail.com> <51EFF957.1040707@stoneleaf.us> <CAPTjJmrnN-13PpKv7LTv6tTH1Tp_zdLj_tsy4NUyDwbm-esB7Q@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.5065.1374700034.3114.python-list@python.org> (permalink)

Show all headers | View raw


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

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


Thread

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

csiph-web