Pythonic love

jmp jeanmichel at sequans.com
Tue Mar 8 12:00:37 EST 2016


On 03/08/2016 05:49 PM, justin walters wrote:
> Correct me if I'm wrong, but don't python generators usually use the yield
> statement so they can be used in list comprehensions?

Hello,

Please don't top post.

Generator expressions are different from generator functions. They are 
both generators but use a different syntax.

generator function:

def func(iterable):
   for i in iterable: yield i


the generator expression version would be

(i for i in iterable)


Both have their use cases but everytime you can actually use an 
generator expression, it's probably the correct thing to do.

Cheers,

jm




More information about the Python-list mailing list