The Voidspace Techie Blog

Gravatar 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.


Gravatar Ack, I put that on the wrong post. My apologies.


Name:

Email:

URL:

Comment:  ? 

 

Commenting by HaloScan