I want to make a Python dictionary. I want values like 0.25, 0.30, 0.35 to be keys in this dictionary. The problems is that I have values like 0.264, 0.313, 0.367. I want this values to access the keys e.g. I want every value from 0.25(inclusive) to 0.30(exclusive) to access the value under the key 0.25. Any ideas how to do this? I think I've done that before somehow, but I have no ideas right now. Thanks in advance.
How to make a dictionary, in which multiple values access one value(Python)
163 Views Asked by Borut Flis At
2
Create a subclass of
dictwith adjusted__getitem__,__setitem__,__delitem__,__contains__,get(),pop()andupdate()methods that round the key:This floors any key down to the nearest
0.05multiple when getting, setting or deleting individual keys, as well as when updating the dictionary with multiple keys: