Is there a Python data structure that seamlessly combines a dictionary (with nested dictionaries or lists as values) and a heap, allowing sorting based on a specific value within the nested structures?
Код: Выделить всё
cache = {"key1": {"time": time1, "info": "key1 info"}, "key2": {"time": time2, "info": "key2 info"}, ...}
Код: Выделить всё
cache = {"key1": [time1, "key1 info"], "key2": [time2, "key2 info"], ...}
Current options considered:
- Forming a heap from the dictionary (drawback - expensive operation O(n^2)).
- Implementing a class with separately stored heap and dictionary (drawback - complexity of synchronizing data in the heap and dictionary).
- Simple iteration through the dictionary in O(n). This option is favored for its simplicity but might not be optimal.
- List item
Источник: https://stackoverflow.com/questions/781 ... ionary-and