67Re: [python-iter] Colon syntax: We barely knew thee...
- Mar 3, 20013 Mar 2001 11:57:53 GMT, Marcin 'Qrczak' Kowalczyk <qrczak@...> pisze:
> Unfortunately the slice interface is slow for normal lists, so it's notHere is a backward compatible proposal.
> 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.
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.
try: x = _tmp
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/
^^ SYGNATURA ZASTĘPCZA
- << Previous post in topic Next post in topic >>