Skip to main content

nindex

Classes to provide efficient indexing and slicing operations into a list of objects by certain attribute key.

Installation

pip install ninstall

Usage

  1. Create your list of objects:
class Item():
    def __init__(self, value, name):
        self.value = value
        self.name = name

items = [
    Item(1, "alpha"),
    Item(3, "beta"),
    Item(8, "gamma"),
    Item(22, "delta")
]
  1. Wrap the list in a new Index, and specify which attribute will be the key:
from nindex import Index
itemindex = Index(items, "value")
  1. Quickly look up objects by attribute key:
 # Look for the object with this exact value
item = itemindex[3]
print(item.name)
# 'beta'

# Look for the closest object with less than or equal to this value
item = itemindex.le(20)
print(item.name)
# 'gamma'

# Look for all objects with values in the given range
items = itemindex[2:22] #
for item in items:
    print(item.name)
# 'beta'
# 'gamma'

Limitations

This with only work if:

  • The list is sorted
  • The list doesn't change
  • The keyed attributes don't change
  • The keyed attributes contain no duplicate values

Metadata

Release files for nindex 1.0.0

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

Source distribution (sdist)

Source distribution for nindex 1.0.0
File Size Uploaded Provenance Actions
nindex-1.0.0.tar.gz 3.3 kB Without provenance Details for nindex-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nindex 1.0.0
File Interpreter ABI Platform Actions
nindex-1.0.0-py3-none-any.whl Python 3 none any Details for nindex-1.0.0-py3-none-any.whl

Total release size: 7.1 kB

Release files / nindex-1.0.0.tar.gz

Download URL nindex-1.0.0.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ca6c05523044a8550244986dab1fe387de43082756497c3347c8cd2abc90fd64
BLAKE2b-256 checksum
How to use checksums
9cee48bdd7d9985054bea01e3a60ae9ef3b936fc7b6928ea465f401851a9f3d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

Release files / nindex-1.0.0-py3-none-any.whl

Download URL nindex-1.0.0-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f7e1ca6fab4cb4df2f74832485ffa9b21e06a15aed46846ba6e2452fee3f014
BLAKE2b-256 checksum
How to use checksums
0f44f48a3ac5148ce7ed5ff119c08cabc5c97ab7f183b09590e8dd854361528d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

Security for nindex 1.0.0

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 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