Is there a .net analogue of Python's OrderedDict?
An OrderedDict is a dictionary that remembers the order that keys were first inserted. If a new entry overwrites an existing entry, the original insertion position is left unchanged. Deleting an entry and reinserting it will move it to the end.
I want this precise behaviour.
Python's OrderedDict is a dict subclass that preserves the order in which key-value pairs, commonly known as items, are inserted into the dictionary. When you iterate over an OrderedDict object, items are traversed in the original order. If you update the value of an existing key, then the order remains unchanged.
No it won't become redundant in Python 3.7 because OrderedDict is not just a dict that retains insertion order, it also offers an order dependent method, OrderedDict. move_to_end() , and supports reversed() iteration*.
The only difference between OrderedDict and dict is that, in OrderedDict, it maintains the orders of keys as inserted. In the dict, the ordering may or may not be happen. The OrderedDict is a standard library class, which is located in the collections module.
OrderedDict is over 80% slower than the standard Python dictionary (8.6/4.7≈1.83).
I believe System.Collections.Specialized.OrderedDictionary
behaves like that.
There is no generic implementation of OrderedDictionary collection in "vanilla" .NET, however, you still can write your own or use existing solutions:
OrderedDictionary: A generic implementation of IOrderedDictionary
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With