Functions for performing binary search on sorted lists
Project description
Functions for performing binary search on sorted lists
pip install bisectsearch
Tested against Windows 10 / Python 3.10 / Anaconda
from bisectsearch import (
rightmost_value_equal_to,
leftmost_value_equal_to,
rightmost_value_less_than,
rightmost_value_less_than_or_equal,
leftmost_value_greater_than,
leftmost_value_greater_than_or_equal,
)
l = sorted(list(range(0, 5)) * 3)
print(f'{(h:=rightmost_value_equal_to(l, 4)), l[h]=}')
print(f'{(h:=rightmost_value_equal_to(l, 0)),l[h]=}')
print(f'{(h:=rightmost_value_equal_to(l, 1)),l[h]=}')
print(f'{(h:=leftmost_value_equal_to(l, 4)),l[h]=}')
print(f'{(h:=leftmost_value_equal_to(l, 0)),l[h]=}')
print(f'{(h:=leftmost_value_equal_to(l, 1)),l[h]=}')
print(f'{(h:=rightmost_value_less_than(l, 4)),l[h]=}')
print(f'{(h:=rightmost_value_less_than(l, 2)),l[h]=}')
print(f'{(h:=rightmost_value_less_than(l, 1)),l[h]=}')
print(f'{(h:=rightmost_value_less_than_or_equal(l, 40)),l[h]=}')
print(f'{(h:=rightmost_value_less_than_or_equal(l, 0)),l[h]=}')
print(f'{(h:=rightmost_value_less_than_or_equal(l, 1)),l[h]=}')
print(f'{(h:=leftmost_value_greater_than(l, 2)),l[h]=}')
print(f'{(h:=leftmost_value_greater_than(l, 3)),l[h]=}')
print(f'{(h:=leftmost_value_greater_than(l, 0)),l[h]=}')
print(f'{(h:=leftmost_value_greater_than(l, 1)),l[h]=}')
print(f'{(h:=leftmost_value_greater_than_or_equal(l, 3)),l[h]=}')
print(f'{(h:=leftmost_value_greater_than_or_equal(l, 0)),l[h]=}')
print(f'{(h:=leftmost_value_greater_than_or_equal(l, 1)),l[h]=}')
# output
# (h:=rightmost_value_equal_to(l, 4)), l[h]=(14, 4)
# (h:=rightmost_value_equal_to(l, 0)),l[h]=(2, 0)
# (h:=rightmost_value_equal_to(l, 1)),l[h]=(5, 1)
# (h:=leftmost_value_equal_to(l, 4)),l[h]=(12, 4)
# (h:=leftmost_value_equal_to(l, 0)),l[h]=(0, 0)
# (h:=leftmost_value_equal_to(l, 1)),l[h]=(3, 1)
# (h:=rightmost_value_less_than(l, 4)),l[h]=(11, 3)
# (h:=rightmost_value_less_than(l, 2)),l[h]=(5, 1)
# (h:=rightmost_value_less_than(l, 1)),l[h]=(2, 0)
# (h:=rightmost_value_less_than_or_equal(l, 40)),l[h]=(14, 4)
# (h:=rightmost_value_less_than_or_equal(l, 0)),l[h]=(2, 0)
# (h:=rightmost_value_less_than_or_equal(l, 1)),l[h]=(5, 1)
# (h:=leftmost_value_greater_than(l, 2)),l[h]=(9, 3)
# (h:=leftmost_value_greater_than(l, 3)),l[h]=(12, 4)
# (h:=leftmost_value_greater_than(l, 0)),l[h]=(3, 1)
# (h:=leftmost_value_greater_than(l, 1)),l[h]=(6, 2)
# (h:=leftmost_value_greater_than_or_equal(l, 3)),l[h]=(9, 3)
# (h:=leftmost_value_greater_than_or_equal(l, 0)),l[h]=(0, 0)
# (h:=leftmost_value_greater_than_or_equal(l, 1)),l[h]=(3, 1)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
bisectsearch-0.11.tar.gz
(3.3 kB
view hashes)
Built Distribution
Close
Hashes for bisectsearch-0.11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbcb999f998b0cc747432b9abebf4ab493d138e267ba6fed237cacef4bc38844 |
|
MD5 | ad170cf6dfeedf4c92170108c4196193 |
|
BLAKE2b-256 | f86059ea9b7aea35ccd4593db415406ed4d6c733c71876086d7caf31ea7cff12 |