[Python-Dev] Tricky way of of creating a generator via a comprehension expression (original) (raw)
Ethan Furman ethan at stoneleaf.us
Wed Nov 22 12:32:09 EST 2017
- Previous message (by thread): [Python-Dev] Tricky way of of creating a generator via a comprehension expression
- Next message (by thread): [Python-Dev] Tricky way of of creating a generator via a comprehension expression
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 11/22/2017 09:15 AM, Paul Moore wrote:
1. List comprehensions expand into nested for/if statements in the "obvious" way - with an empty list created to start and append used to add items to it. 1a. Variables introduced in the comprehension don't "leak" (see below). 2. Generator expressions expand into generators with the same "nested loop" behaviour, and a yield of the generated value. 3. List comprehensions are the same as list(the equivalent generator expression).
For what it's worth, that is how I understand it.
--
Ethan
- Previous message (by thread): [Python-Dev] Tricky way of of creating a generator via a comprehension expression
- Next message (by thread): [Python-Dev] Tricky way of of creating a generator via a comprehension expression
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]