iterators and views of lists

Anh Hai Trinh anh.hai.trinh at gmail.com
Wed Dec 16 07:58:58 EST 2009


On Dec 16, 10:39 am, Brendan Miller <catph... at catphive.net> wrote:
> I was trying to reimplement some of the c++ library of generic
> algorithms in c++ in python, but I was finding that this is
> problematic to do this in a generic way because there isn't any
> equivalent of c++'s forward iterators, random access iterators, etc.
> i.e. all python iterators are just input iterators that can't mutate
> the sequence they iterate over nor move backwards or by an arbitrary
> offset.

You might be interested in this library <http://pypi.python.org/pypi/
stream>.

You can easily create arbitrary "slice", for example

  i = mylist >> takei(primes())

will return an iterator over the items of mylist with a prime number
index, given that primes() return an iterator over prime numbers.

I'm not familiar with forward/random-access/bidirectional iterators.



More information about the Python-list mailing list