non-copy slices

Tim Golden mail at timgolden.me.uk
Wed Nov 18 16:44:51 CET 2009


tbourden at doc.ic.ac.uk wrote:
> Hi,
> 
> I was looking for a facility similar to slices in python library that would
> avoid the implicit creation of a new list and copy of elements that is the
> default behaviour. Instead I'd rather have a lazy iteratable object on the
> original sequence. Well, in the end I wrote it myself but I was wondering if
> I missed sth in the library. If I didn't is there a particular reason there
> isn't sth like that? I find it hard to believe that all slice needs have
> strictly copy semantics.

I suspect that itertools is your friend, specifically itertools.islice

TJG



More information about the Python-list mailing list