A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-March/043524.html below:

[Python-Dev] Possible resolution of generatorexpressionvariablecapture dilemma

[Python-Dev] Possible resolution of generatorexpressionvariablecapture dilemma [Python-Dev] Possible resolution of generatorexpressionvariablecapture dilemmaGuido van Rossum guido at python.org
Thu Mar 25 19:01:38 EST 2004
> With regard to generator expressions, isn't Guido leaning
> back towards not having any variable capture?

Right.

> Or is he un-leaning-back again? This is all getting very
> confusing...

Paul Dubois told me he thought that an example I used in my keynote
today (which would fail without capture) would be an attractive
nuisance for scientists (since it looked just like a reasonable way to
compute an outer product).  I'm not sure the argument holds, because
an outer product would typically be created as a list of lists, not a
list of generators.

The example I used was:

F = []
for i in range(10):
    F.append(x*i for x in range(10))

It would end up creating 10 generators referencing the variable i with
value 9.

The version using list comprehensions of course works:

F = []
for i in range(10):
    F.append([x*i for x in range(10)])

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4