Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print just the value of a dictionary term for a specific key in Python

I am wondering what I do in Python if I have a dictionary and I want to print out just the value for a specific key.

It will be in a variable as well as in:

dict = {'Lemonade':["1", "45", "87"], 'Coke:["23", "9", "23"] 'Water':["98", "2", "127"}
inp = input("Select key to print value for!" + "/r>>> ")
if inp in dict:
    #Here is where I would like it to print the Value list for the key that is entered.

I am running Python 3.3

like image 545
cbbcbail Avatar asked Dec 09 '22 18:12

cbbcbail


1 Answers

I have taken the liberty of renaming your dict variable, to avoid shadowing the built-in name.

dict_ = {
    'Lemonade': ["1", "45", "87"], 
    'Coke': ["23", "9", "23"], 
    'Water': ["98", "2", "127"],
}
inp = input("Select key to print value for!" + "/r>>> ")
if inp in dict_:
    print(dict_[inp])
like image 57
wim Avatar answered Dec 11 '22 07:12

wim