I have a code snippet that arranges a dictionary alphabetically. Is there a way to select the ith key in an ordered dictionary and return its corresponding value? i.e.
import collections initial = dict(a=1, b=2, c=2, d=1, e=3) ordered_dict = collections.OrderedDict(sorted(initial.items(), key=lambda t: t[0])) print(ordered_dict) OrderedDict([('a', 1), ('b', 2), ('c', 2), ('d', 1), ('e', 3)])
I want to have some function along the vein ...
select = int(input("Input dictionary index"))
How can this be achieved? Thanks.
(Similar to Accessing Elements in orderdict , but I only want to output the value of the key-value pair.)
Pingk
source share