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

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

Expand Messages
  • qrczak@knm.org.pl
    Mar 3, 2001
      3 Mar 2001 11:57:53 GMT, Marcin 'Qrczak' Kowalczyk <qrczak@...> pisze:

      > Unfortunately the slice interface is slow for normal lists, so it's not
      > clear how a for loop could know which is better to use. In all cases
      > both will work, but sometimes one is cheaper, and sometimes the other.

      Here is a backward compatible proposal.
      The meaning of 'for x in seq: statement' is as follows:

      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
      _tmp = _tmp[1:]

      indexing_iterator is a proxy which emulates sliced iteration interface
      in terms of indexed iteration interface.

      __("< Marcin Kowalczyk * qrczak@... http://qrczak.ids.net.pl/
    • Show all 27 messages in this topic