Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!news2.euro.net!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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'read.': 0.03; 'function,': 0.09; 'cc:addr:python-list': 0.11; '-tkc': 0.16; 'd[key]': 0.16; 'dict': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'pythonic': 0.16; 'wrote:': 0.18; 'result.': 0.19; 'code,': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**1': 0.23; 'expanded': 0.24; 'header:In-Reply-To:1': 0.27; 'easier': 0.31; 'discovery': 0.31; 'subject:the': 0.34; 'but': 0.35; 'charset:us- ascii': 0.36; 'needed': 0.38; 'rather': 0.38; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'results': 0.69; 'received:50.22': 0.84 Date: Mon, 15 Apr 2013 14:10:42 -0500 From: Tim Chase To: Barrett Lewis Subject: Re: Process tuple contents on the fly In-Reply-To: References: <20130415135013.58430065@bigbox.christie.dr> X-Mailer: Claws Mail 3.7.6 (GTK+ 2.20.1; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com Cc: Python Mailing List 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: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366052947 news.xs4all.nl 2640 [2001:888:2000:d::a6]:55731 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43639 On 2013-04-15 12:05, Barrett Lewis wrote: > > d = {} > > for key, d[key] in (("this",18), ("that",17), ("other",38)): > > print key > > do_something(d) > > Why not use a dict comprehension? > d = {k:v for k,v in (("this",18), ("that",17), ("other",38))} > > I feel this is more straightforward and easier to read. the results > are the same however. In the particular case I did it in, I needed the incremental results passed to a function, not just the final result. I don't think this made it into the final code, rather it was expanded to be more readable. But the discovery made me feel a disturbance in the Pythonic force of the universe. :*) -tkc