Skip to main content

Alternative slicing and indexing

Project description

The altslice package provides a number of Slicer classes which can be used to index and slice sequences using alternative indexing. For example:

from altslice import CategoricalSlicer

months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
sales = [100, 200, 250, 300, 333, 400]

slicer = CategoricalSlicer(months)

# sales total from January

# sales from Febuary until May


The following Slicers are provided in the library:

  • CategoricalSlicer : Index using discrete categories.
  • UniformSlicer : Index using evenly spaced numbers with a specific interval.
  • SeqeuenceSlicer : Index using a sorted sequence of numbers.
  • OneBasedSlicer : One-based indexing.


altslice can be installed using pip:

pip install altslice


altslice uses pytest for testing. The test suite can be executed using py.test.

One-based indexing

If desired the list container can be adjusted to use one-based indexing:

from altslice import OneBasedSlicer

slicer = OneBasedSlicer()

class list(list):
    def __getitem__(self, x):
        return super(list, self).__getitem__(slicer[x])

This adjustment is not recommended.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for altslice, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size altslice-0.1.0-py2.py3-none-any.whl (4.4 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size altslice-0.1.0.tar.gz (6.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page