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
File details
Details for the file altslice-0.1.0.tar.gz
.
File metadata
- Download URL: altslice-0.1.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b351a489fa4811250f8ee53b2463359bbde1f9d71dc2973545dca65c6d9d2044 |
|
MD5 | e8343cb3b3bfb01b4ba142c9bd6e8029 |
|
BLAKE2b-256 | b00fc3274a1526700306a3e94da7c3efdd3221050714d4a5c4d469dad4652e15 |
File details
Details for the file altslice-0.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: altslice-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ffc64bd462c0bb40c5f586fd5a8d55360ab84f6a7eafc64701be858db20e6d4 |
|
MD5 | 354b96d7cd5aeb2fb01bdc1bf8dd6ac3 |
|
BLAKE2b-256 | e719fc1257c65a066c1d2dc5eb972f197e44f20771729b392c2316ad58fb5b33 |