Skip to main content

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:

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:

>>> from ordinal_list import OrdinalList

Create an OrdinalList with some fruits

>>> ordinal_list = OrdinalList(["apple", "banana", "cherry"])

Access elements using ordinal indices

>>> 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:

>>> 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:

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

And you can extend the list with more items:

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

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

>>> 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

Metadata

Release files for ordinal-list 0.2.0

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

Built distribution (wheel)

Table of built distributions (wheels) for ordinal-list 0.2.0
File Interpreter ABI Platform
ordinal_list-0.2.0-py3-none-any.whl Python 3 none any Details

Release files / ordinal_list-0.2.0-py3-none-any.whl

Download URL ordinal_list-0.2.0-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f8e0ffb4bbd9f6d6a78e9053a379b78ef3d6c4d189af4d158636d8556e3da36e
BLAKE2b-256 checksum
How to use checksums
baf53a691a3bb5b71c7678398887b12813213e05679d2d3291e94c6ba6bc25a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file

0.1.1

1 release file

0.1.0

1 release file

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