Python 3: dict & dict.keys()

Ian Kelly ian.g.kelly at gmail.com
Wed Jul 24 11:15:06 EDT 2013


On Wed, Jul 24, 2013 at 8:58 AM, Skip Montanaro <skip at 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().



More information about the Python-list mailing list