Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #99535 > unrolled thread
| Started by | dieter <dieter@handshake.de> |
|---|---|
| First post | 2015-11-26 08:17 +0100 |
| Last post | 2015-11-26 08:17 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: What does a list comprehension do dieter <dieter@handshake.de> - 2015-11-26 08:17 +0100
| From | dieter <dieter@handshake.de> |
|---|---|
| Date | 2015-11-26 08:17 +0100 |
| Subject | Re: What does a list comprehension do |
| Message-ID | <mailman.116.1448522274.20593.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web