Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.055 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.01; 'iterate': 0.09; 'keys,': 0.09; 'subject:design': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '"in"': 0.16; 'collections': 0.16; 'dictionaries': 0.16; 'iteration': 0.16; 'keys.': 0.16; 'subject:Language': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'value.': 0.19; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply- To:1': 0.27; "d'aprano": 0.31; 'steven': 0.31; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'should': 0.36; 'sometimes': 0.38; 'pm,': 0.38; 'that,': 0.38; 'bad': 0.39; 'how': 0.40; 'act': 0.63; 'forward': 0.65; 'natural': 0.68; 'dict,': 0.84; 'dict.': 0.84; 'mistakes,': 0.84; 'more:': 0.84; 'thing,': 0.91; 'examine': 0.93; 'contrary': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=fTHhnp/Yn5vJaUo8jmeAm/PS7ftkIo5qvU+Xz/Ip53I=; b=aWcf8IYcTmHBIo4/ZdqbnViIx2PbKGmTqLEph89W9t03Pj4PaL3MVe/rjAKCQQB71O hdULcXS3vn2dfVTZ9oZREhfLDHKEXhUZzDfIiePC1vjUIX/x1irWvciUFO0Q9Br7oedx 99/g3Cwe6Y/V8VGmAjc4RX6229O9feAkYYYWmECs0tsHgoEz1a6rDN0bMyThJqd4Rusg XfoddzHtqgLpASl+9aufJwaNRNDMja4LSqnvWr3+1r9N+j0N42B5YAJRxK5C8w55uLvk bUctETybwZm6jaF0dGY6X1JweYtLNOxGWpzWQN7TBdYp/9w8VO86nLgOZzUFANa1opAF sYMw== X-Received: by 10.182.143.103 with SMTP id sd7mr2793370obb.70.1379011069898; Thu, 12 Sep 2013 11:37:49 -0700 (PDT) Sender: Ned Batchelder Date: Thu, 12 Sep 2013 14:37:47 -0400 From: Ned Batchelder User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: Markus Rother Subject: Re: Language design References: <522eb795$0$29999$c3e8da3$5496439d@news.astraweb.com> <523206EC.8090404@markusrother.de> In-Reply-To: <523206EC.8090404@markusrother.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1379011079 news.xs4all.nl 15887 [2001:888:2000:d::a6]:51427 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54077 On 9/12/13 2:24 PM, Markus Rother wrote: > On 10.09.2013 08:09, Steven D'Aprano wrote: >> What design mistakes, traps or gotchas do you think Python has? Gotchas >> are not necessarily a bad thing, there may be good reasons for it, but >> they're surprising. > I have one more: > > Dictionaries should iterate over their items instead of their keys. I understand the natural desire for this, and I sometimes forget and have to add a ".items()" to my loops. But if you consider how "in" should work with dicts, it's only reasonable that "k in d" examine if a key is in a dict, not if an item is in a dict. And once you have "in" working like that, it's reasonable for iteration to work on keys. Dicts act like collections of keys, each with an associated value. --Ned. > Looking forward to contrary opinions. > > Greets, > Markus