iter(callable, sentinel)

W

Will McGugan

Hi,

I've been using Python for years, but I recently encountered something
in the docs I wasnt familar with. That is, using two arguements for
iter(). Could someone elaborate on the docs and maybe show a typical use
case for it?


Thanks,

Will McGugan
 
S

Simon Forman

Will said:
Hi,

I've been using Python for years, but I recently encountered something
in the docs I wasnt familar with. That is, using two arguements for
iter(). Could someone elaborate on the docs and maybe show a typical use
case for it?


Thanks,

Will McGugan

I just found out about that recently too.

help(iter) shows this:
Help on built-in function iter in module __builtin__:

iter(...)
iter(collection) -> iterator
iter(callable, sentinel) -> iterator

Get an iterator from an object. In the first form, the argument
must
supply its own iterator, or be a sequence.
In the second form, the callable is called until it returns the
sentinel.
 
S

Simon Forman

S

Simon Forman

Will said:
Hi,

I've been using Python for years, but I recently encountered something
in the docs I wasnt familar with. That is, using two arguements for
iter(). Could someone elaborate on the docs and maybe show a typical use
case for it?


Thanks,

Will McGugan

Also, FWIW, GvR said this (parenthetically) about a week ago on the
Python-3000 list: "I also think that the two-argument form
iter(function, sentinel) is not very successful or useful and might be
dropped, but that's a separate issue."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top