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[slicer['Jan']]
# sales from Febuary until May
sales[slicer['Jan':'May']]
Slicers
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.
Install
altslice can be installed using pip:
pip install altslice
Testing
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for altslice-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ffc64bd462c0bb40c5f586fd5a8d55360ab84f6a7eafc64701be858db20e6d4 |
|
MD5 | 354b96d7cd5aeb2fb01bdc1bf8dd6ac3 |
|
BLAKE2b-256 | e719fc1257c65a066c1d2dc5eb972f197e44f20771729b392c2316ad58fb5b33 |