islice ==> [::]

George Sakkis george.sakkis at gmail.com
Fri Mar 7 21:55:29 EST 2008


On Mar 7, 7:49 am, bearophileH... at lycos.com wrote:
> I find itertools.islice() useful, so for Python 3.x I may like to see
> it removed from the itertools module, and the normal slicing syntax
> [::] extended to work with generators/iterators too.
>
> from itertools import islice
> primes = (x for x in xrange(1,999) if all(x % y for y in xrange(2,
> x)))
> print list(islice(primes, 0, 20))
> ==>
> print list(primes[:20])
>
> Bye,
> bearophile

I had posted some time ago an OO wrapper of itertools; slice notation
for islice was one motivation: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498272

George



More information about the Python-list mailing list