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/2000-July/007349.html below:

[Python-Dev] List comprehension syntax (Features for Python 2.0)

[Python-Dev] List comprehension syntax (Features for Python 2.0)Skip Montanaro skip@mojam.com (Skip Montanaro)
Tue, 25 Jul 2000 13:41:17 -0500 (CDT)
    >> [for x in range(100): x*2]

    Fredrik> fwiw, I read that as:

    Fredrik>     [
    Fredrik>         for x in range(100):
    Fredrik>             x * 2
    Fredrik>     ]

    Fredrik> which makes no sense at all.

It makes perfect sense.  You read it correctly as far as I can tell.  Using
Greg's patch, I get what you'd expect from a simple for loop:

    >>> [x*2 for x in range(10)]
    [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]

It occurred to me a little bit ago to suggest that we just allow complete
statements within list constructors.  The semantics would be that any
objects left on the stack at the end of the statements would constitute the
elements of the list.  Is that too weird?

Skip




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