Retrieve value from key : Index : Dictionary PYTHON TUTORIALS


PYTHON TUTORIALS » Dictionary » Index »

 

Retrieve value from key


validkeys = (1,2,3)
keyGenDict={'keys':[1,2,3],1:'blue',2:'fast',3:'test','key':2}

def show_key (key):
    if(key in validkeys):
        keyVal = (keyGenDict["keys"])[key-1]
        print "Key = " + keyGenDict[keyVal]
    else:
        print("Invalid key")

val = keyGenDict["key"]
show_key(val)



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Dictionary
» Index