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


Groups > comp.lang.python > #51142

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

References <51EF2AD8.3080105@stoneleaf.us> <ksnrr9$k4t$1@ger.gmane.org> <CAHVvXxQGCFJe7ud+mwh4zhnq5F7xvHJX1pCtGCjMaFtjBwY=iQ@mail.gmail.com> <CANc-5UzRx6ow+FZ7QMW1wD6ZAZeVONaS0hXCNRZGZ2_hebMN=w@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2013-07-24 09:15 -0600
Subject Re: Python 3: dict & dict.keys()
Newsgroups comp.lang.python
Message-ID <mailman.5044.1374678950.3114.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Jul 24, 2013 at 8:58 AM, Skip Montanaro <skip@pobox.com> wrote:
>> What do you mean? Why would you want to create a temporary list just to
>> iterate over it explicitly or implicitly (set, sorted, max,...)?
>
> Because while iterating over the keys, he might also want to add or
> delete keys to/from the dict.  You can't do that while iterating over
> them in-place.

None of the (set, sorted, max, ...) cases will add or delete keys
while iterating.  For the occasional for loop where the programmer
does want to do that, you can still explicitly create a temporary list
with list().

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


Thread

Re: Python 3: dict & dict.keys() Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-24 09:15 -0600

csiph-web