Path: csiph.com!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '(so': 0.07; 'cc:addr :python-list': 0.09; 'creighton': 0.09; 'worked,': 0.09; 'python': 0.10; 'thursday,': 0.13; 'subject:python': 0.14; 'thu,': 0.15; '24,': 0.16; '>>on': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterating': 0.16; 'iteration': 0.16; 'loops': 0.16; 'wrote:': 0.16; 'laura': 0.18; 'nested': 0.18; '>>>': 0.20; 'student': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'sep': 0.22; 'suppose': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'fri,': 0.27; 'message- id:@mail.gmail.com': 0.27; '-0700,': 0.29; 'dictionary': 0.29; 'code': 0.30; "d'aprano": 0.33; 'steven': 0.33; 'similar': 0.33; 'skip:d 20': 0.34; 'received:google.com': 0.35; 'mapping': 0.35; 'but': 0.36; 'subject:: ': 0.37; 'wanted': 0.37; 'version': 0.38; 'where': 0.40; 'some': 0.40; 'your': 0.60; 'policy': 0.63; 'today': 0.65; 'saw': 0.77; 'batchelder': 0.84; 'chrisa': 0.84; 'me!': 0.84; 'utc-4,': 0.84; 'to:none': 0.91; 'habit': 0.91; 'write:': 0.91; 'not:': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=hHT9stw8j4IJz8RPr+S/wKbdRpt3XD0apap+KXvaKWc=; b=T9Rm5mtNSC1P+05R7nb9C64m3mt6Xe7stxOWFjeoLoErqN2E+XYwTYfINewLtf0DK+ kQvQ6s4Unet87He86/Ak/CMKpInY7cILMff3pWe1JgJCUAvVk/k1Nu+i3Ud2krHdjXlz aC5uUStLdQxQNVvtUABMt/yFSCTbLxFUeEHyW5O3J+6Pkssto7KUJs0LzKXTt+mke1ef C9oiYN8MXd4GC25mDTXI8A+AsObqwwddyeoK6h/xsPx6GbD+2z851IgwI/K/UiPpdOm2 nIzPC5paFSIOKk4T3sRbvOw+lwaYlz3P/R3P5niBQYy85LsslnV+igAzw8Xs7f+pTF3w jBBQ== MIME-Version: 1.0 X-Received: by 10.50.178.145 with SMTP id cy17mr33165184igc.92.1443131342457; Thu, 24 Sep 2015 14:49:02 -0700 (PDT) In-Reply-To: <201509242108.t8OL8wQs026851@fido.openend.se> References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> <00884c56-4c94-406b-9902-b94dda9d66b3@googlegroups.com> <201509242108.t8OL8wQs026851@fido.openend.se> Date: Fri, 25 Sep 2015 07:49:02 +1000 Subject: Re: Idiosyncratic python From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1443131740 news.xs4all.nl 23771 [2001:888:2000:d::a6]:38549 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:97096 On Fri, Sep 25, 2015 at 7:08 AM, Laura Creighton wrote: > In a message of Thu, 24 Sep 2015 13:46:27 -0700, Ned Batchelder writes: >>On Thursday, September 24, 2015 at 2:02:38 AM UTC-4, Steven D'Aprano wrote: >>> What are your favorite not-wrong-just-weird Python moments? >> >>I've seen this a number of times: >> >> dict_of_values.update({'key': some_value}) >> >>why not: >> >> dict_of_values['key'] = some_value >> >>I've considered writing a Pylint plugin to flag these... >> >>--Ned. > > A student today had a similar version of this one: > > Every time he wanted to change the value of dictionary mapping he would > write: > w={'key': new_value} > dict_of_values.update(w) That's a new one on me! The oddest dictionary code any of my students has come out with (so far!) was a slavish habit of always iterating over them thus: for k,v in some_dict.items(): where some_dict is the only part that changed. So everywhere through the code - even in nested loops - all dictionary iteration used "k" and "v". But I suspect it's exactly the same. Saw some code somewhere, found that it worked, used it. If you don't understand something, don't change it... which is a good policy in general, I suppose :) ChrisA