0
Using a dictionary key in a for loop or if statement
I want to use strings from a list to find keys in a dictionary so that I can return the associated value. This is what I’ve tried but my syntax is wrong: dict = {‘foot’:12.0, ‘cm’:0.394, ‘yard’:36.0} list = [‘foot’, ‘yard’] for unit in list: for meas in dict: if unit == dict[meas][0]: Print(dict[meas][1]
4 Antworten
+ 1
Jan Markus what is the ‘_’ after the names? Is it part of the syntax?
+ 1
Jan Markus thank you.
0
Jan Markus
I am still having trouble referencing the key in a dictionary. Below is my code for the Code Coach problem called Ballpark: