Negative array indicies and slice()

alex23 wuwei23 at gmail.com
Mon Oct 29 00:44:56 EDT 2012


On Oct 29, 2:09 pm, Andrew <andrewr3m... at gmail.com> wrote:
> I use this arbitrary range code *often* so I need a general purpose solution.
> I looked up slice() but the help is of no use, I don't even know how I might
> overload it to embed some logic to concatenate ranges of data; nor even if
> it is possible.

Slices are passed in if provided to __getitem__/__setitem__/
__delitem__, so you'd need to override it at the list level:

    class RangedSlicer(list):
        def __getitem__(self, item):
            # map item.start, .stop and .step to your own semantics

Then wrap your lists with your RangedSlicer class as needed.



More information about the Python-list mailing list