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
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])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With