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


Groups > comp.lang.python > #51142

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

Path csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.032
X-Spam-Evidence '*H*': 0.95; '*S*': 0.01; 'programmer': 0.03; 'explicitly': 0.05; 'subject:Python': 0.06; 'iterate': 0.09; 'keys,': 0.09; 'subject:()': 0.09; '24,': 0.16; 'iterating': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'skip': 0.24; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'keys': 0.31; 'cases': 0.33; "can't": 0.35; 'received:google.com': 0.35; 'add': 0.35; 'list': 0.37; 'to:addr:python-list': 0.38; 'that,': 0.38; 'does': 0.39; 'delete': 0.39; 'to:addr:python.org': 0.39; 'temporary': 0.65; 'subject: & ': 0.68; 'jul': 0.74; 'dict.': 0.84; 'max,': 0.84; 'to/from': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=+KVKq3Zv7xUTGT98cdzjKm/9KhGDartEM20aPV3NbKU=; b=h+QHxm2ojkth8toaSryv/aSIUI6KPzSKCJCLibw4Qwob8GN6Jig0jsmR+rahWJLtGk +Op99wNFW69OrB9QIngiwvKAyLn0PKno7cE1Alg3J6YLJmWTC7wJcqDevb4F8h9KqNW1 x2O+SbrDDQFI+wyvMh7Qz7r0BNMwNqbskmNj1eCYWJspjuM9CgQ85zhDpimW8lvJI83l /WYZ8OwhB3lbxQwubLeWynHK+FtahvTQ0iD55uOrD/xtJKmdp6L+GCkp5C6BOjtEMA6i /RtgX9/lrPd7dZrRieliQ3NwxFOUYdChj4oV0OUHgGnJxi2uyRwAtkQaJt0GM2fVWd/+ 4Msg==
X-Received by 10.68.217.7 with SMTP id ou7mr42949761pbc.8.1374678946472; Wed, 24 Jul 2013 08:15:46 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <CANc-5UzRx6ow+FZ7QMW1wD6ZAZeVONaS0hXCNRZGZ2_hebMN=w@mail.gmail.com>
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 Wed, 24 Jul 2013 09:15:06 -0600
Subject Re: Python 3: dict & dict.keys()
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5044.1374678950.3114.python-list@python.org> (permalink)
Lines 12
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1374678950 news.xs4all.nl 15954 [2001:888:2000:d::a6]:34049
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:51142

Show key headers only | 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