Usage¶
Basic Usage¶
All keys in a sorted dictionary must be of the same type, which is determined when the first key-value pair is inserted into it. The values, though, can be of any type.
from pysorteddict import SortedDict
d = SortedDict()
d["honestly"] = "weight"
d["gain is"] = 31.692
d["times"] = "easier than"
d["losing"] = ["weight"]
assert d.key_type is str
for key, value in d.items():
print(key, "->", value)
The above Python script will output the keys in ascending order.
gain is -> 31.692
honestly -> weight
losing -> ['weight']
times -> easier than
Demo¶
You can try pysorteddict out in the JupyterLite REPL below. When you click on ‘Try Now’, it will start a Pyodide kernel and run some code to install pysorteddict (using one of the hosted wheels) and import it. This will take a few seconds.
Try Now
Try Now