Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #51156
| References | (1 earlier) <ksnrr9$k4t$1@ger.gmane.org> <CAHVvXxQGCFJe7ud+mwh4zhnq5F7xvHJX1pCtGCjMaFtjBwY=iQ@mail.gmail.com> <51EFF957.1040707@stoneleaf.us> <CAPTjJmrnN-13PpKv7LTv6tTH1Tp_zdLj_tsy4NUyDwbm-esB7Q@mail.gmail.com> <ksp26j$sfp$1@ger.gmane.org> |
|---|---|
| Date | 2013-07-25 03:58 +1000 |
| Subject | Re: Python 3: dict & dict.keys() |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5057.1374688738.3114.python-list@python.org> (permalink) |
On Thu, Jul 25, 2013 at 3:17 AM, Terry Reedy <tjreedy@udel.edu> wrote: > On 7/24/2013 12:34 PM, Chris Angelico wrote: > >> 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. > > This is > coupled with the fact that the default meaning of 'item in collection' is > that iterating over 'collection' eventually produces 'item' or a value equal > to 'item'. Ahh, that makes sense. I never thought of iteration and 'in' being connected like that, but yes, that's a solid reason for doing it that way. ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Python 3: dict & dict.keys() Chris Angelico <rosuav@gmail.com> - 2013-07-25 03:58 +1000
csiph-web