Skip to main content

pylookups

Excel-style lookup, filter, and sort functions for plain Python lists — no pandas or numpy required.

Docs: https://lalit2206.github.io/pylookups/

pip install pylookups

The install name is pylookups, but the import name is pylookup:

from pylookup import vlookup, xlookup, match, index, index_match, filter, unique, sort

Note: filter shadows Python's built-in filter in any module that imports it by name. If you still need the built-in in the same file, use the namespaced style instead:

import pylookup as pl

pl.filter([1, 2, 3, 4], lambda x: x > 2)

Install (local development)

python -m venv .venv
.venv\Scripts\activate        # Windows
pip install -e ".[dev]"
pytest

Functions

Row/column positions follow Excel's convention: 1-based, not 0-based.

match(lookup_value, lookup_array, match_type=0)

Position (1-based) of lookup_value in lookup_array. match_type: 0 exact, 1 largest value <= target (ascending array), -1 smallest value >= target (descending array). Raises NotFoundError.

index(array, row_num, col_num=None)

Value at row_num (and col_num for a 2D table). Omit col_num to get the whole row.

index_match(return_array, lookup_value, lookup_array, match_type=0)

index + match combined: find lookup_value in lookup_array, return the item at that position in return_array.

vlookup(lookup_value, table, col_index, exact=True)

Search the first column of table (list of rows) for lookup_value, return the value at col_index of the matching row.

hlookup(lookup_value, table, row_index, exact=True)

Search the first row of table for lookup_value, return the value at row_index of the matching column.

xlookup(lookup_value, lookup_array, return_array, if_not_found=None, match_mode=0, search_mode=1)

Search lookup_array for lookup_value, return the corresponding item from return_array. match_mode: 0 exact, -1 exact or next smaller, 1 exact or next larger. search_mode: 1 first-to-last, -1 last-to-first. Returns if_not_found instead of raising when nothing matches.

filter(array, condition, if_empty=None)

Keep items where condition is true. condition is a predicate function or a boolean list the same length as array.

unique(array, keep="first")

Distinct items, order preserved. keep="last" keeps the last occurrence instead of the first.

sort(array, by=None, key=None, reverse=False)

Sort a flat list, or a 2D table by column by (1-based). key overrides both with a custom function.

Example

table = [
    ["id", "name", "score"],
    [1, "alice", 90],
    [2, "bob", 75],
    [3, "carol", 60],
]

vlookup(2, table, 2)                     # "bob"
xlookup(3, [1, 2, 3], ["a", "b", "c"])   # "c"
sort(table[1:], by=3, reverse=True)      # highest score first (skip header row)

See src/examples/basic.py for more.

Publishing to PyPI

pip install build twine
python -m build
twine upload dist/*

Metadata

Release files for pylookups 0.1.1

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

Source distribution (sdist)

Source distribution for pylookups 0.1.1
File Size Uploaded
pylookups-0.1.1.tar.gz 9.3 kB Details

Built distribution (wheel)

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

Total release size: 16.9 kB

Release files / pylookups-0.1.1.tar.gz

Download URL pylookups-0.1.1.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
236b8a584635d7c26ebc306a1aed90913c5817aaecd40978da8dd3b9f0128ab2
BLAKE2b-256 checksum
How to use checksums
ec66b692e2a83816eab6849b4bfafd62df93e6d8d73665a0f86ccbb3b33bb438
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / pylookups-0.1.1-py3-none-any.whl

Download URL pylookups-0.1.1-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f5d681a9d4321a921c8443447850e2a12e8268a3ac4b9550c798507c614b1d9a
BLAKE2b-256 checksum
How to use checksums
923e5a9d40470fde28c28374e3bdeb5af8956da78c74644bca64405202ed7169
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release history Release notifications | RSS feed

0.1.3

2 release files

0.1.2

2 release files

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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