iter(callable, sentinel)

Discussion in 'Python' started by Will McGugan, Jul 27, 2006.

  1. Will McGugan

    Will McGugan Guest

    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

    --
    work: http://www.kelpiesoft.com
    blog: http://www.willmcgugan.com
    Will McGugan, Jul 27, 2006
    #1
    1. Advertising

  2. Will McGugan

    Simon Forman Guest

    Will McGugan wrote:
    > 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
    >
    > --
    > work: http://www.kelpiesoft.com
    > blog: http://www.willmcgugan.com


    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.
    Simon Forman, Jul 27, 2006
    #2
    1. Advertising

  3. Will McGugan

    Simon Forman Guest

    Will McGugan wrote:
    > 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
    >
    > --
    > work: http://www.kelpiesoft.com
    > blog: http://www.willmcgugan.com


    D'oh! You said *elaborate*... Sorry. Fredrik Lundh gives a great
    example of it's use in this thread:
    http://groups.google.ca/group/comp.lang.python/browse_frm/thread/b3ab8141c492bb21/e3f71597917afaa3

    Peace,
    ~Simon
    Simon Forman, Jul 27, 2006
    #3
  4. Will McGugan

    Simon Forman Guest

    Will McGugan wrote:
    > 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
    >
    > --
    > work: http://www.kelpiesoft.com
    > blog: http://www.willmcgugan.com


    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."
    Simon Forman, Jul 27, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. d.j.

    sentinel

    d.j., Apr 22, 2004, in forum: C++
    Replies:
    3
    Views:
    1,797
    John Harrison
    Apr 22, 2004
  2. thomas
    Replies:
    23
    Views:
    842
    James Kanze
    Feb 26, 2008
  3. Gennaro Prota
    Replies:
    1
    Views:
    334
    Gennaro Prota
    Aug 21, 2008
  4. exiquio
    Replies:
    2
    Views:
    520
    exiquio
    Oct 7, 2008
  5. Ulrich Eckhardt
    Replies:
    6
    Views:
    95
    Peter Otten
    Jul 12, 2013
Loading...

Share This Page