My (late) beef with Simple Generator syntax (PEP 255)

François Pinard pinard at iro.umontreal.ca
Wed Nov 13 19:47:23 EST 2002


[Cameron Horn]

> >def foo(): return iter(tuple())

> Which is the obvious, clear and consistent way to create a generator that
> doesn't do anything.

I was to suggest:

   def foo(): return iter([])

but using a tuple is probably tinily faster.  No need to call tuple(),
however, just write an empty tuple constant:

   def foo(): return iter(())

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard





More information about the Python-list mailing list