ListLookup
Wrapper for faster lookups in a list of objects/dictionaries. ATTENTION Do not modify list once indexes are created!
from listlookup import ListLookup
cities = ListLookup([
{"id": 1, "country": "us", name: "Atlanta"},
{"id": 2, "country": "us", name: "Miami"},
{"id": 3, "country": "uk", name: "Britain"},
{"id": 4, "country": "ca", "name": "Barrie"},
])
cities.index("id", lambda d: d['id'], True)
cities.index("country", lambda d: d['country'])
list(cities.lookup(id=1))
>>> [{"id": 1, "country": "us", name: "Atlanta"}]
list(cities.lookup(country="us", preserve_order=True))
>>> [{"id": 1, "country": "us", name: "Atlanta"}, {"id": 2, "country": "us", name: "Miami"}]
list(cities.lookup(id=2, country="uk"))
>>> []
cities.index('name', lambda d: d['name'])
list(cities.lookup(name=lambda val: val.startswith('B'))
>>> [{"id": 3, "country": "uk", name: "Britain"}, {"id": 4, "country": "ca", "name": "Barrie"}]
Case insensitive index
This is not supported out of the box. You need to use same case for index and lookup values. E.g. use .lower()
from listlookup import ListLookup
cities = ListLookup([
{"id": 1, "country": "us", name: "Atlanta"},
{"id": 2, "country": "us", name: "Miami"},
{"id": 3, "country": "uk", name: "Britain"},
{"id": 4, "country": "ca", "name": "Barrie"},
])
cities.index("country_ci", lambda d: d['country'].lower())
list(cities.lookup(country_ci="UK".lower()))
>>> [{"id": 3, "country": "uk", name: "Britain"}]
Multiple pointers per item
You can have same record be referenced by multiple values. In the following example "uk" and "uk2" correspond to the same record because they are returned as alternatives during indexing:
from listlookup import ListLookup
cities = ListLookup([
{"id": 1, "country": "us", name: "Atlanta"},
{"id": 2, "country": "us", name: "Miami"},
{"id": 3, "country": "uk", name: "Britain"},
{"id": 4, "country": "ca", "name": "Barrie"},
])
cities.index("country_alt", lambda d: [d['country'], "%s2" % d['country']], multiple=True)
list(cities.lookup(country_alt="uk"))
>>> [{"id": 3, "country": "uk", name: "Britain"}]
list(cities.lookup(country_alt="uk2"))
>>> [{"id": 3, "country": "uk", name: "Britain"}]
Metadata
Release files for list-lookup 1.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| list-lookup-1.0.7.tar.gz | 3.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| list_lookup-1.0.7-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 8.3 kB
Release files / list-lookup-1.0.7.tar.gz
| Download URL | list-lookup-1.0.7.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7e0f1b584519b621d8d597057e0e1d8349f233df23056451a4f21f9106a1875
|
|
BLAKE2b-256 checksum How to use checksums |
866490aa9a6b18cbfcc59cac900a11083befbf21ea5a98561579ffb1f7886864
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.2
|
Release files / list_lookup-1.0.7-py2.py3-none-any.whl
| Download URL | list_lookup-1.0.7-py2.py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
277f883cc9449b7450eab2195c3768e22d74d3d914f2ac18e9ad83f661e066ec
|
|
BLAKE2b-256 checksum How to use checksums |
7f5b39cd180417e1f6b27351ebd3ac2d28e8aedf7c107795f1b80c3be5e5499e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.2
|
Security for list-lookup 1.0.7
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.