Skip to main content

nindex

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nindex-1.0.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nindex-1.0.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file nindex-1.0.0.tar.gz.

File metadata

  • Download URL: nindex-1.0.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for nindex-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ca6c05523044a8550244986dab1fe387de43082756497c3347c8cd2abc90fd64
MD5 0958821ecec7cf489f36c75b9cd80e56
BLAKE2b-256 9cee48bdd7d9985054bea01e3a60ae9ef3b936fc7b6928ea465f401851a9f3d6

See more details on using hashes here.

File details

Details for the file nindex-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: nindex-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for nindex-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f7e1ca6fab4cb4df2f74832485ffa9b21e06a15aed46846ba6e2452fee3f014
MD5 7cf8e4c65feeb9c9d88c12f5849da65f
BLAKE2b-256 0f44f48a3ac5148ce7ed5ff119c08cabc5c97ab7f183b09590e8dd854361528d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page