Loading ...
Sorry, an error occurred while loading the content.

68Re: [python-iter] Colon syntax: We barely knew thee...

Expand Messages
  • Ka-Ping Yee
    Mar 3, 2001
      On 3 Mar 2001 qrczak@... wrote:
      > try: _tmp = seq.__iterator__()
      > except AttributeError: _tmp = indexing_iterator(seq)
      > # Types with fast x[1:] can just def __iterator__(self): return self
      > # Types which don't define __iterator__ get the old iteration protocol.
      > while 1:
      > try: x = _tmp[0]
      > except IndexError: break
      > statement
      > _tmp = _tmp[1:]
      >
      > indexing_iterator is a proxy which emulates sliced iteration interface
      > in terms of indexed iteration interface.

      I can see that this would work, but i don't understand why you prefer

      while 1:
      body(iter[0])
      iter = iter[1:]

      to

      while 1: # when a new-style iterator is available
      body(iter())

      or

      i = 0
      while 1: # what happens when we use make_iterator()
      body(iter[i])
      i = i + 1

      as the basic stepping operation (in the above, think of "body"
      as the body of the for-loop and "iter" as the iterator object).


      -- ?!ng

      "The biggest cause of trouble in the world today is that the stupid people
      are so sure about things and the intelligent folk are so full of doubts."
      -- Bertrand Russell
    • Show all 27 messages in this topic