Skip to main content

slice-a-portion

PyPI Tests Changelog License

get the i/n slice of a sequence

Installation

Install this library using pip:

pip install slice-a-portion

Usage

There are two functions

>>> from slice_a_portion import slice_by_coefficients, slice_by_portion

   slice_by_coefficients(sequence: Sequence, start: Optional[float] = None, end: Optional[float] = None)
        Return the slice between the coefficients `start` and `end`
        between 0 and 1.
        
        Corner elements may be repeated in consecutive slices.
        
        >>> slice_by_coefficients(abc", 0, 0.333)
        'a'
        >>> slice_by_coefficients("abc", 0.666, 1)
        'c'
        >>> slice_by_coefficients("abcd", 0, 0.499)
        'ab'
        >>> slice_by_coefficients("abcd", None, 0.499)
        'ab'
        >>> slice_by_coefficients("abcd", 0.5, 1)
        'cd'
        >>> slice_by_coefficients("abcd", 0.5)    # until the end
        'cd'
   slice_by_fraction(sequence: Sequence, i: int, n: int)
       Split a sequence in `n` slices and then return the i-th (1-indexed).
       The last slice will be longer if the sequence can't be splitted even-sized or
       n is greater than the sequence's size.
       
       >>> from slice_a_portion import slice_by_fraction
       >>> slice_by_fraction("abcdefghi", 1, 2)
       'abcd'
       >>> slice_by_fraction("abcdefghi", 2, 2)
       'efghi'
       >>> slice_by_fraction("abcdefghi", 1, 3)
       'abc'
       >>> slice_by_fraction("abcdefghi", 2, 3)
       'def'
       >>> slice_by_fraction("abcdefghi", 3, 3)
       'ghi'        
       >>>

Development

To contribute to this library, first checkout the code. Then create a new virtual environment:

cd slice-a-portion
python -m venv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

pip install -e '.[test]'

To run the tests:

pytest

Metadata

Release files for slice-a-portion 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for slice-a-portion 0.1
File Size Uploaded Provenance
slice-a-portion-0.1.tar.gz 6.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for slice-a-portion 0.1
File Interpreter ABI Platform
slice_a_portion-0.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.0 kB

Release files / slice-a-portion-0.1.tar.gz

Download URL slice-a-portion-0.1.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
65f36805cae3490045a64b752202926ca2273c4da3938a60478e093df215753d
BLAKE2b-256 checksum
How to use checksums
b342929b502dcc8f6a3921d7b50e87921105a45577dd25ebb8038d491b7d00ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / slice_a_portion-0.1-py3-none-any.whl

Download URL slice_a_portion-0.1-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
417a20c9e20404af7566c5a7a2643cf76a7fcb8bbd1f6c9b0f0d1e785090ebe6
BLAKE2b-256 checksum
How to use checksums
4c961f65608969916614daab814e8f9fdbcd933264b2ad697cbea015511e0bcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Security for slice-a-portion 0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page