[Python-ideas] Sequence views
grant.jenks at gmail.com
Sun Jul 17 19:00:23 EDT 2016
> > On Jul 17, 2016 3:23 PM, "Serhiy Storchaka" <storchaka at gmail.com> wrote:
> > Maybe it's time to add a new module for sequence-specific functions (seqtools?). It should contain at least two classes or fabric functions:
> > 1. A view that represents a sliced subsequence. Lazy equivalent of seq[start:end:step]. This feature is implemented in third-party module dataview .
> On Sun, Jul 17, 2016 at 3:21 PM, Wes Turner <wes.turner at gmail.com> wrote:
SortedContainers implements exactly that as a method on SortedList as:
SortedList.islice(start=None, stop=None, reverse=False)
Returns an iterator that slices self from start to stop index,
inclusive and exclusive respectively.
When reverse is True, values are yielded from the iterator in reverse order.
Both start and stop default to None which is automatically inclusive
of the beginning and end.
Return type: iterator
I chose to limit the stride to 1 or -1 using the keyword parameter
"reverse." No complaints though it differs from traditional slice
More information about the Python-ideas