slice-a-portion


Nameslice-a-portion JSON
Version 0.1 PyPI version JSON
download
home_page
Summaryget the i/n slice of a sequence
upload_time2024-01-18 22:31:12
maintainer
docs_urlNone
authorMartín Gaitán
requires_python>=3.8
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # slice-a-portion

[![PyPI](https://img.shields.io/pypi/v/slice-a-portion.svg)](https://pypi.org/project/slice-a-portion/)
[![Tests](https://github.com/mgaitan/slice-a-portion/actions/workflows/test.yml/badge.svg)](https://github.com/mgaitan/slice-a-portion/actions/workflows/test.yml)
[![Changelog](https://img.shields.io/github/v/release/mgaitan/slice-a-portion?include_prereleases&label=changelog)](https://github.com/mgaitan/slice-a-portion/releases)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/mgaitan/slice-a-portion/blob/main/LICENSE)

get the i/n slice of a sequence

## Installation

Install this library using `pip`:

```bash
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:
```bash
cd slice-a-portion
python -m venv venv
source venv/bin/activate
```
Now install the dependencies and test dependencies:
```bash
pip install -e '.[test]'
```
To run the tests:
```bash
pytest
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "slice-a-portion",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "Mart\u00edn Gait\u00e1n",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/b3/42/929b502dcc8f6a3921d7b50e87921105a45577dd25ebb8038d491b7d00ee/slice-a-portion-0.1.tar.gz",
    "platform": null,
    "description": "# slice-a-portion\n\n[![PyPI](https://img.shields.io/pypi/v/slice-a-portion.svg)](https://pypi.org/project/slice-a-portion/)\n[![Tests](https://github.com/mgaitan/slice-a-portion/actions/workflows/test.yml/badge.svg)](https://github.com/mgaitan/slice-a-portion/actions/workflows/test.yml)\n[![Changelog](https://img.shields.io/github/v/release/mgaitan/slice-a-portion?include_prereleases&label=changelog)](https://github.com/mgaitan/slice-a-portion/releases)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/mgaitan/slice-a-portion/blob/main/LICENSE)\n\nget the i/n slice of a sequence\n\n## Installation\n\nInstall this library using `pip`:\n\n```bash\npip install slice-a-portion\n```\n\n\n## Usage\n\nThere are two functions\n```\n>>> from slice_a_portion import slice_by_coefficients, slice_by_portion\n\n```\n\n\n\n```\n   slice_by_coefficients(sequence: Sequence, start: Optional[float] = None, end: Optional[float] = None)\n        Return the slice between the coefficients `start` and `end`\n        between 0 and 1.\n        \n        Corner elements may be repeated in consecutive slices.\n        \n        >>> slice_by_coefficients(abc\", 0, 0.333)\n        'a'\n        >>> slice_by_coefficients(\"abc\", 0.666, 1)\n        'c'\n        >>> slice_by_coefficients(\"abcd\", 0, 0.499)\n        'ab'\n        >>> slice_by_coefficients(\"abcd\", None, 0.499)\n        'ab'\n        >>> slice_by_coefficients(\"abcd\", 0.5, 1)\n        'cd'\n        >>> slice_by_coefficients(\"abcd\", 0.5)    # until the end\n        'cd'\n ```\n\n ```\n    slice_by_fraction(sequence: Sequence, i: int, n: int)\n        Split a sequence in `n` slices and then return the i-th (1-indexed).\n        The last slice will be longer if the sequence can't be splitted even-sized or\n        n is greater than the sequence's size.\n        \n        >>> from slice_a_portion import slice_by_fraction\n        >>> slice_by_fraction(\"abcdefghi\", 1, 2)\n        'abcd'\n        >>> slice_by_fraction(\"abcdefghi\", 2, 2)\n        'efghi'\n        >>> slice_by_fraction(\"abcdefghi\", 1, 3)\n        'abc'\n        >>> slice_by_fraction(\"abcdefghi\", 2, 3)\n        'def'\n        >>> slice_by_fraction(\"abcdefghi\", 3, 3)\n        'ghi'        \n        >>>\n```\n\n## Development\n\nTo contribute to this library, first checkout the code. Then create a new virtual environment:\n```bash\ncd slice-a-portion\npython -m venv venv\nsource venv/bin/activate\n```\nNow install the dependencies and test dependencies:\n```bash\npip install -e '.[test]'\n```\nTo run the tests:\n```bash\npytest\n```\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "get the i/n slice of a sequence",
    "version": "0.1",
    "project_urls": {
        "CI": "https://github.com/mgaitan/slice-a-portion/actions",
        "Changelog": "https://github.com/mgaitan/slice-a-portion/releases",
        "Homepage": "https://github.com/mgaitan/slice-a-portion",
        "Issues": "https://github.com/mgaitan/slice-a-portion/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4c961f65608969916614daab814e8f9fdbcd933264b2ad697cbea015511e0bcd",
                "md5": "3851d56a08be7539342d94045e0637fa",
                "sha256": "417a20c9e20404af7566c5a7a2643cf76a7fcb8bbd1f6c9b0f0d1e785090ebe6"
            },
            "downloads": -1,
            "filename": "slice_a_portion-0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3851d56a08be7539342d94045e0637fa",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 7061,
            "upload_time": "2024-01-18T22:31:11",
            "upload_time_iso_8601": "2024-01-18T22:31:11.141276Z",
            "url": "https://files.pythonhosted.org/packages/4c/96/1f65608969916614daab814e8f9fdbcd933264b2ad697cbea015511e0bcd/slice_a_portion-0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b342929b502dcc8f6a3921d7b50e87921105a45577dd25ebb8038d491b7d00ee",
                "md5": "99180ffb81234245bd0b9b72ae4677cd",
                "sha256": "65f36805cae3490045a64b752202926ca2273c4da3938a60478e093df215753d"
            },
            "downloads": -1,
            "filename": "slice-a-portion-0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "99180ffb81234245bd0b9b72ae4677cd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 6929,
            "upload_time": "2024-01-18T22:31:12",
            "upload_time_iso_8601": "2024-01-18T22:31:12.564022Z",
            "url": "https://files.pythonhosted.org/packages/b3/42/929b502dcc8f6a3921d7b50e87921105a45577dd25ebb8038d491b7d00ee/slice-a-portion-0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-18 22:31:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mgaitan",
    "github_project": "slice-a-portion",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "slice-a-portion"
}
        
Elapsed time: 0.15835s