In Python 2:
If you want to access the key:
>>> ordered_dict = OrderedDict([('a', 1), ('b', 2), ('c', 2), ('d', 1), ('e', 3)])
>>> ordered_dict.keys()[2]
'c'
If want to access the value:
>>> ordered_dict.values()[2]
2
If you're using Python 3, you can convert the KeysView
object returned by the keys
method by wrapping it as a list:
>>> list(ordered_dict.keys())[2]
'c'
>>> list(ordered_dict.values())[2]
2
Not the prettiest solution, but it works.