How do I get a key and its value from a dictionary?

I have a dictionary, and I want to get a key & value SEPERATED out of it:

values = {
    "a": 123,
    "b": 173,
    "c": 152,
    "d": 200,
    "e": 714,
    "f": 71
}

Is there a way to do something like this:

dictValue = values[2] #I know this will be an error
dictKey = "c"
dictValue = 152

Thanks!

>Solution :

Create an auxiliary dictionary with integer keys:

d = dict(enumerate(values.items()))
dictKey, dictValue = d[2]
#('c', 152)

Leave a Reply