RangeDictionary
RangeDictionary package provides Range and RangeDict classes.
from range_dictionary import Range, RangeDict
Range
Range objects represent an interval. They can be open, semi-open or closed.
r1 = Range(1, 2) # open
r2 = Range[1, 2] # closed
r3 = Range(1, 2, closed_left=True) # semi-open
r4 = Range(1, 2, closed_right=True) # semi-open
2 in r1 # False
2 in r2 # True
RangeDict
RangeDict objects are dictionaries whose keys are Range objects. They can be initialized using any iterable of 2 int/float values (the corresponding Ranges are open by default).
rd = RangeDict({
(1, 2) : "first",
Range[2, 5] : "second",
Range(5, 7, closed_right=True) : "third",
Range(7, float("inf")) : "fourth"
})
Accessing an int/float from a RangeDict returns its corresponding value.
3.5 in rd # True
rd[3.5] # "second"
RangeDicts behave similarly to standard dictionaries.
rd[Range(7, 9)] = "fifth"
rd.insert(Range[9, 11], "sixth")
del rd[Range[2, 5]]
rd.remove(Range(1, 2))
rd.get(8) # "fifth"
rd.get(100) # None
rd2 = RangeDict()
rd == rd2 # False
rd.clear()
rd == rd2 # True
# return generators, order not guaranteed
rd.keys()
rd.values()
rd.items()
# return sorted lists
rd.keys_sorted()
rd.values_sorted()
rd.items_sorted()
# merge RangeDicts
rd3 = rd | rd2
rd.update(rd2)
Acknowledgements
Inspired by rangedict by WKPlus.
Metadata
Release files for RangeDictionary 1.0.2
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 | |
|---|---|---|---|---|
| RangeDictionary-1.0.2.tar.gz | 7.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| RangeDictionary-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.4 kB
Release files / RangeDictionary-1.0.2.tar.gz
| Download URL | RangeDictionary-1.0.2.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b4642679bf8a3b161026ef08a1e498d7fd76cb69e9f933e1699d839963af0f54
|
|
BLAKE2b-256 checksum How to use checksums |
8cb68348d70c273ba1dbb4844ede3991525f240b617bd50c6cf77fd76d5488bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Release files / RangeDictionary-1.0.2-py3-none-any.whl
| Download URL | RangeDictionary-1.0.2-py3-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
802ac607bbd4e6009de54b40bc34a744d1aa6e7ccbe81e60de16a7a2f19e007b
|
|
BLAKE2b-256 checksum How to use checksums |
f110570be5651d7d371f64c776a63b1add0d8d336c0a265f6c3c8bbe3ac2b066
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Security for RangeDictionary 1.0.2
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.