[Python-Dev] itertools addition: getitem()

Raymond Hettinger python at rcn.com
Mon Jul 9 18:43:50 CEST 2007


From: "Guido van Rossum" <guido at python.org>
> But doesn't the very same argument also apply against islice(), which
> you just offered as an alternative?

Not really.  The use cases for islice() typically do not involve
repeated slices of an iterator unless it is slicing off the front
few elements on each pass.  In contrast, getitem() is all about
grabbing something other than the frontmost element and seems
to be intended for repeated calls on the same iterator.  And its
support for negative indices seems somewhat weird in the
context of general purpose iterators:  getitem(genprimes(), -1).

I'll study Walter's use case but my instincts say that adding
getitem() will do more harm than good.


Raymond


More information about the Python-Dev mailing list