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)
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 fo
Steven D'Aprano 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 form is rare, but
still it's sometim
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(