How to make an empty generator?

Arnaud Delobelle arnodel at googlemail.com
Thu Feb 18 18:49:08 EST 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