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


Groups > comp.lang.python > #99535

Re: What does a list comprehension do

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From dieter <dieter@handshake.de>
Newsgroups comp.lang.python
Subject Re: What does a list comprehension do
Date Thu, 26 Nov 2015 08:17:43 +0100
Lines 23
Message-ID <mailman.116.1448522274.20593.python-list@python.org> (permalink)
References <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <877fldnm9z.fsf@handshake.de> <5655BCDB.4020905@rece.vub.ac.be>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace news.uni-berlin.de pdYcao6eOZcK/jKog6HB1Auykc+bf/oN8ADSQQvyQZlg==
Cancel-Lock sha1:+D03L598A/xJDPYPpp9w+RcFv1k=
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'essentially': 0.04; 'expressions': 0.07; 'subject:skip:c 10': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; 'discussions': 0.15; '"x"': 0.16; 'python3.': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'of.': 0.18; '(or': 0.23; 'header :User-Agent:1': 0.26; 'subject:list': 0.26; 'header:X-Complaints- To:1': 0.26; 'addition,': 0.27; 'equivalent': 0.27; 'especially': 0.32; 'list': 0.34; 'gives': 0.35; 'but': 0.36; '(and': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'charset:us-ascii': 0.37; 'late': 0.38; 'someone': 0.38; 'why': 0.39; 'sure': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'avoid': 0.61; 'binding': 0.66; 'received:217': 0.66; 'pardon': 0.84; 'schreef': 0.84
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host pd9e08978.dip0.t-ipconnect.de
User-Agent Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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>
Xref csiph.com comp.lang.python:99535

Show key headers only | View raw


Antoon Pardon <antoon.pardon@rece.vub.ac.be> writes:

> Op 20-11-15 om 08:49 schreef dieter:
>> In addition, the last few days have had two discussions in this list
>> demonstrating the conceptial difficulties of late binding -- one of them:
>>
>>       Why does "[lambda x: i * x for i in range(4)]" gives
>>       a list of essentially the same functions?
>
> Can you (or someone else) explain what a list comprehension is equivallent of.
> Especially in python3.

I am not sure about "Python3" (never used it), but in Python 2,
the simple list comprehension "[x for x in l]" is roughly equivalent to:

    result = []
    for x in l: result.append(x)
    ... the list comprehension result is in "result" which (however) is not bound ...

In Python 3, "x" might not be bound as well - to harmonise list comprehension
with generator expressions (and avoid the confusion, that a local
(temporary) binding can change the value of a global binding).

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


Thread

Re: What does a list comprehension do dieter <dieter@handshake.de> - 2015-11-26 08:17 +0100

csiph-web