Steven D'Aprano wrote:
The iter() built-in takes two different forms, the familiar
iter(iterable) we all know and love, and an alternative form:
iter(callable, sentinel)
I've never seen this second form in actual code. Does anyone use it, and
if so, what use-cases do you have?
I found
On 3/11/2011 1:43 AM, Steven D'Aprano wrote:
The iter() built-in takes two different forms, the familiar
iter(iterable) we all know and love, and an alternative form:
iter(callable, sentinel)
E.g.:
T = -1
def func():
... global T
... T += 1
... return T
...
it = iter(func, 3)
The iter() built-in takes two different forms, the familiar
iter(iterable) we all know and love, and an alternative form:
iter(callable, sentinel)
E.g.:
T = -1
def func():
... global T
... T += 1
... return T
...
it = iter(func, 3)
next(it)
0
next(it)
1
next(it)
2
next(it)
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:
I've never seen this second form in actual code. Does anyone use it,
and if so, what use-cases do you have?
Since APIs that signal end-of-iteration by returning a sentinel have
fallen out of favor in Python (with good reason), this