Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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: UNSURE 0.228 X-Spam-Level: ** X-Spam-Evidence: '*H*': 0.58; '*S*': 0.04; 'constructor': 0.09; 'subject:skip:c 10': 0.09; 'dict': 0.16; 'expression.': 0.16; 'no- op': 0.16; 'wrote:': 0.18; 'compare': 0.26; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'received:google.com': 0.35; 'revert': 0.36; 'thanks': 0.36; "i'll": 0.36; 'subject:?': 0.36; 'example,': 0.37; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'expression': 0.60; 'first': 0.61; 'back': 0.62; 'more': 0.64; 'mar': 0.68; '10000': 0.68; 'frank': 0.68; '2015': 0.84; 'dict()': 0.84; 'mistake': 0.91 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=YdgNyfVr8H/sqYtgpcZGcNUtAAPKVc7w/cDhn8vHnds=; b=BVvnQL/UKxJIpFL/yplRBpSJA77eoOQF/9rEW+i8l8aOHkqHvsNoiuZlZo9Qe/tZjX y/ZPdmM1Kgz6ZQQdQ1mRfoM2pDsYSOLNT2xD1XUPOObtnx8UHbrVLg0sA8O9EF4BHFTl rq1sCF+lSbkxIxgxQVtiJ7/5bAjcj7tfhuQarhedS3qnZREo7OTIXXCA2cHNbvVi0VaZ Fogj2DQCV7K+HJE2UmjCkwNxUQ+sxxLqpWp6y0jbslMavFZ8UbvgksWO/YLZGMlZ/rIi 3Om353soNW05Ngc1JS0CYSWxXcj42RjO7AlQ9VUf80Mw3X4Szu9GENldsAtd8PJElJO1 MPAQ== X-Received: by 10.70.130.69 with SMTP id oc5mr42667874pdb.89.1426607334807; Tue, 17 Mar 2015 08:48:54 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <87fv95fom0.fsf@jester.gateway.sonic.net> <87wq2hfibu.fsf@jester.gateway.sonic.net> From: Ian Kelly Date: Tue, 17 Mar 2015 09:48:14 -0600 Subject: Re: Dict comprehensions - improvement to docs? To: Python Content-Type: text/plain; charset=UTF-8 X-Mailman-Approved-At: Tue, 17 Mar 2015 18:04:35 +0100 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 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: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1426611876 news.xs4all.nl 2861 [2001:888:2000:d::a6]:35978 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3941 X-Received-Body-CRC: 2391059023 Xref: csiph.com comp.lang.python:87643 On Tue, Mar 17, 2015 at 12:44 AM, Frank Millman wrote: > Thanks for the explanation. I'll try not to make that mistake again. > > However, to go back to the original example, we want to compare a dict > comprehension with a dict() constructor using a generator expression. > > Let's see if I have got this one right - > > C:\>python -m timeit -s "x=range(65, 91); y=[chr(z) for z in x]" "dict((a, > b) for a, b in zip(x, y))" > 10000 loops, best of 3: 49.6 usec per loop > > C:\>python -m timeit -s "x=range(65, 91); y=[chr(z) for z in x]" "{a: b for > a, b in zip(x, y)}" > 10000 loops, best of 3: 25.8 usec per loop Why did you revert back to the no-op generator expression in the first case instead of the more efficient dict(zip(x, y))?