ordinal-list


Nameordinal-list JSON
Version 0.2.0 PyPI version JSON
download
home_pageNone
SummaryA Python library that uses ordinal numbers to work with lists.
upload_time2024-05-10 17:46:35
maintainerNone
docs_urlNone
authorJimmy Jensen
requires_python>=3.8
licenseThe MIT License (MIT) Copyright (c) [2024] [Jimmy Jensen] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords ordinal list indexing python 0-based 1-based
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Ordinal List

Ordinal List is a Python library that extends the functionality of Python's built-in list to use ordinal numbers for indexing. This allows users to access list elements using ordinal notations like '1st', '2nd', '3rd', etc., instead of zero-based indexing.

## Features

- Easy to use interface similar to Python's native list.
- Supports negative indexing similar to Python lists.
- Raises clear and descriptive errors for invalid inputs.

## Installation

To install the Ordinal List library, run the following command in your terminal:

```bash
pip install ordinal-list
```

This will download and install the latest version of Ordinal List from the Python Package Index (PyPI). After installation, you can import and use the library in your Python projects.

## Examples

Here's how to get started with the Ordinal List library:

```python
>>> from ordinal_list import OrdinalList
```

Create an OrdinalList with some fruits
```python
>>> ordinal_list = OrdinalList(["apple", "banana", "cherry"])
```
Access elements using ordinal indices

```python
>>> print(ordinal_list["1st"])
apple
>>> print(ordinal_list["2nd"])
banana
>>> print(ordinal_list["3rd"])
cherry
>>> print(ordinal_list["-1st"])
cherry
```

Negative ordinals are also supported, as shown in the example above.

If you try to access an element with an invalid ordinal, the library will raise a descriptive error:
```python
>>> try:
>>>    print(ordinal_list["0th"]) # Invalid ordinal, will raise an error
>>> except Exception as e:
>>>    print(e)
```


You can also set items using ordinal indices:

```python
>>> ordinal_list["1st"] = "strawberry"
>>> print(ordinal_list["1st"])
strawberry
```

And you can extend the list with more items:

```python
>>> ordinal_list.extend(["kiwi", "mango"])
>>> print(ordinal_list["5th"])
mango
```

There is also a great helper method for programatically iterating an OrdinalList:

```python
>>> from ordinal_list import ordinal_range

>>> ordinal_list = OrdinalList(["apple", "banana", "cherry", "date", "elderberry"])
>>> for ordinal in ordinal_range("1st", "5th"):
>>>    print(ordinal_list[ordinal])
apple
banana
cherry
date
elderberry
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ordinal-list",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "ordinal, list, indexing, python, 0-based, 1-based",
    "author": "Jimmy Jensen",
    "author_email": null,
    "download_url": null,
    "platform": null,
    "description": "# Ordinal List\n\nOrdinal List is a Python library that extends the functionality of Python's built-in list to use ordinal numbers for indexing. This allows users to access list elements using ordinal notations like '1st', '2nd', '3rd', etc., instead of zero-based indexing.\n\n## Features\n\n- Easy to use interface similar to Python's native list.\n- Supports negative indexing similar to Python lists.\n- Raises clear and descriptive errors for invalid inputs.\n\n## Installation\n\nTo install the Ordinal List library, run the following command in your terminal:\n\n```bash\npip install ordinal-list\n```\n\nThis will download and install the latest version of Ordinal List from the Python Package Index (PyPI). After installation, you can import and use the library in your Python projects.\n\n## Examples\n\nHere's how to get started with the Ordinal List library:\n\n```python\n>>> from ordinal_list import OrdinalList\n```\n\nCreate an OrdinalList with some fruits\n```python\n>>> ordinal_list = OrdinalList([\"apple\", \"banana\", \"cherry\"])\n```\nAccess elements using ordinal indices\n\n```python\n>>> print(ordinal_list[\"1st\"])\napple\n>>> print(ordinal_list[\"2nd\"])\nbanana\n>>> print(ordinal_list[\"3rd\"])\ncherry\n>>> print(ordinal_list[\"-1st\"])\ncherry\n```\n\nNegative ordinals are also supported, as shown in the example above.\n\nIf you try to access an element with an invalid ordinal, the library will raise a descriptive error:\n```python\n>>> try:\n>>>    print(ordinal_list[\"0th\"]) # Invalid ordinal, will raise an error\n>>> except Exception as e:\n>>>    print(e)\n```\n\n\nYou can also set items using ordinal indices:\n\n```python\n>>> ordinal_list[\"1st\"] = \"strawberry\"\n>>> print(ordinal_list[\"1st\"])\nstrawberry\n```\n\nAnd you can extend the list with more items:\n\n```python\n>>> ordinal_list.extend([\"kiwi\", \"mango\"])\n>>> print(ordinal_list[\"5th\"])\nmango\n```\n\nThere is also a great helper method for programatically iterating an OrdinalList:\n\n```python\n>>> from ordinal_list import ordinal_range\n\n>>> ordinal_list = OrdinalList([\"apple\", \"banana\", \"cherry\", \"date\", \"elderberry\"])\n>>> for ordinal in ordinal_range(\"1st\", \"5th\"):\n>>>    print(ordinal_list[ordinal])\napple\nbanana\ncherry\ndate\nelderberry\n```\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT)  Copyright (c) [2024] [Jimmy Jensen]  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "A Python library that uses ordinal numbers to work with lists.",
    "version": "0.2.0",
    "project_urls": {
        "Repository": "https://github.com/mrjsj/ordinal-list"
    },
    "split_keywords": [
        "ordinal",
        " list",
        " indexing",
        " python",
        " 0-based",
        " 1-based"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "baf53a691a3bb5b71c7678398887b12813213e05679d2d3291e94c6ba6bc25a2",
                "md5": "14df387469676e869b54942b4b1440ae",
                "sha256": "f8e0ffb4bbd9f6d6a78e9053a379b78ef3d6c4d189af4d158636d8556e3da36e"
            },
            "downloads": -1,
            "filename": "ordinal_list-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "14df387469676e869b54942b4b1440ae",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 5480,
            "upload_time": "2024-05-10T17:46:35",
            "upload_time_iso_8601": "2024-05-10T17:46:35.664823Z",
            "url": "https://files.pythonhosted.org/packages/ba/f5/3a691a3bb5b71c7678398887b12813213e05679d2d3291e94c6ba6bc25a2/ordinal_list-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-10 17:46:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mrjsj",
    "github_project": "ordinal-list",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "ordinal-list"
}
        
Elapsed time: 0.23080s