How to make an empty generator?

Arnaud Delobelle arnodel at googlemail.com
Fri Feb 19 00:49:08 CET 2010


On 18 Feb, 23:33, Ben Finney <ben+pyt... at benfinney.id.au> wrote:
[...]
> No need to define functions or classes; let a generator expression take
> care of it for you::
>
>     >>> foo = (x for x in list())
>     >>> foo.next()
>     Traceback (most recent call last):
>       File "<stdin>", line 1, in <module>
>     StopIteration

What about

    foo = iter('')

Then there is the interesting

    foo = iter(int, 0)

:)

--
Arnaud



More information about the Python-list mailing list