iter(callable, sentinel)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Will McGugan

    #1

    iter(callable, sentinel)

    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
  • Simon Forman

    #2
    Re: iter(callable, sentinel)


    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.

    Comment

    • Simon Forman

      #3
      Re: iter(callable, sentinel)

      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:


      Peace,
      ~Simon

      Comment

      • Simon Forman

        #4
        Re: iter(callable, sentinel)

        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 (parentheticall y) 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."

        Comment

        Working...