|
|
|
generator = (f(value) for value in iterable if value > 0)
That syntax is just syntactic sugar for an older way of doing Python generator functions, which just requires defining a function that uses the "yield" keyword instead of "return". In other words, it's equivalent to:
def generator():
for value in interable:
if value > 0:
yield f(value)
Of course, the former syntax is more concise in this case, but the extended syntax allows for more complicated constructions.
L33tminion |
Homepage |
08/09/04 - 5:25 pm | #
|
|
Ack, I put that on the wrong post. My apologies.
L33tminion |
Homepage |
08/09/04 - 5:27 pm | #
|
|
|
Commenting by HaloScan
|