Can we know the position of items in Python’s ordered dictionary?
For example:
If I have dictionary:
// Ordered_dict is OrderedDictionary
Ordered_dict = {"fruit": "banana", "drinks": "water", "animal": "cat"}
Now how do I know in which position cat belongs to?
Is it possible to get an answer like:
position (Ordered_dict["animal"]) = 2 ? or in some other way?
You may get a list of keys with the
keysproperty:Better performance could be achieved with the use of
iterkeys()though.For those using Python 3: