Skip to main content

A sorted dictionary with nearest-key lookup.

Project description

FuzzySortedDict is a sorted dictionary with nearest-key lookups.

>>> from FuzzySortedDict import FuzzySortedDict
>>> d = FuzzySortedDict()
>>> d[1] = 1
>>> d[2] = 2
>>> d[1.75]
2

FuzzySortedDict can be particularly useful for sparsely populated ranges, such as when working with time.

>>> from FuzzySortedDict import FuzzySortedDict
>>> import datetime
>>> d = FuzzySortedDict()
>>> d[datetime.datetime(2000, 1, 1, 12, 0, 0)] = 1
>>> d[datetime.datetime(2000, 1, 1, 12, 0, 4)] = 2
>>> d[datetime.datetime(2000, 1, 1, 12, 0, 1)]
1

Project details


Supported by

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