I have the key of a python dictionary and I want to get the corresponding index in the dictionary. Suppose I have the following dictionary,
d = { 'a': 10, 'b': 20, 'c': 30}
Is there a combination of python functions so that I can get the index value of 1, given the key value 'b'?
d.??('b')
I know it can be achieved with a loop or lambda (with a loop embedded). Just thought there should be a more straightforward way.
question from:
https://stackoverflow.com/questions/14538885/how-to-get-the-index-with-the-key-in-a-dictionary 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…