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


Groups > comp.lang.python > #87643

Re: Dict comprehensions - improvement to docs?

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 <ian.g.kelly@gmail.com>
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 <me8ige$kjp$1@ger.gmane.org>
References <mailman.410.1426483550.21433.python-list@python.org> <87fv95fom0.fsf@jester.gateway.sonic.net> <mailman.427.1426494675.21433.python-list@python.org> <87wq2hfibu.fsf@jester.gateway.sonic.net> <me664q$hon$1@ger.gmane.org> <CALwzid=u19YMkfJBhbLZi1qh2U9UK4ohY5wco1zO-i3T5AtyOA@mail.gmail.com> <me8ige$kjp$1@ger.gmane.org>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Tue, 17 Mar 2015 09:48:14 -0600
Subject Re: Dict comprehensions - improvement to docs?
To Python <python-list@python.org>
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 <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.498.1426611876.21433.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Tue, Mar 17, 2015 at 12:44 AM, Frank Millman <frank@chagford.com> 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))?

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Dict comprehensions - improvement to docs? "Frank Millman" <frank@chagford.com> - 2015-03-16 07:25 +0200
  Re: Dict comprehensions - improvement to docs? Paul Rubin <no.email@nospam.invalid> - 2015-03-15 23:22 -0700
    Re: Dict comprehensions - improvement to docs? "Frank Millman" <frank@chagford.com> - 2015-03-16 10:30 +0200
      Re: Dict comprehensions - improvement to docs? Paul Rubin <no.email@nospam.invalid> - 2015-03-16 01:38 -0700
        Re: Dict comprehensions - improvement to docs? "Frank Millman" <frank@chagford.com> - 2015-03-16 11:01 +0200
        Re: Dict comprehensions - improvement to docs? Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-16 09:57 -0600
          Re: Dict comprehensions - improvement to docs? Paul Rubin <no.email@nospam.invalid> - 2015-03-16 15:41 -0700
        Re: Dict comprehensions - improvement to docs? "Frank Millman" <frank@chagford.com> - 2015-03-17 08:44 +0200
        Re: Dict comprehensions - improvement to docs? Lele Gaifax <lele@metapensiero.it> - 2015-03-17 15:06 +0100
        Re: Dict comprehensions - improvement to docs? Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-17 09:48 -0600
        Re: Dict comprehensions - improvement to docs? "Frank Millman" <frank@chagford.com> - 2015-03-18 10:01 +0200
        Re: Dict comprehensions - improvement to docs? Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-18 02:39 -0600

csiph-web