Add `dict` move_to_end(last=False) functionality in the `OrderedDict` documentation
Documentation
In the OrderedDict Objects documentation it states:
"A regular dict does not have an efficient equivalent for OrderedDict’s od.move_to_end(k, last=False) which moves the key and its associated value to the leftmost (first) position."
This can easily be accomplished in two ways:
value = d.pop(key)
d = {key: value, **d}
value = d.pop(key) # Remove the key-value pair from the dictionary
new_dict = {key: value} # Create a new dictionary with the key-value pair
new_dict.update(d) # Add the rest of the original dictionary
I'm not sure those qualify as "efficient".
I'm not sure those qualify as "efficient".
You're right. Definitely not space, maybe they're not too inefficient time wise?
I'm not sure those qualify as "efficient".
You're right. Definitely not space, maybe they're not too inefficient time wise?
The proposed workaround requires O(n) complexity in both space and time, while with an OrderedDict only O(1) is required in both space and time.
The proposed workaround requires O(n) complexity in both space and time, while with an OrderedDict only O(1) is required in both space and time.
Thank you for the correction.