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]

21st May 2021, 1:42 AM
Ellison
Ellison - avatar
4 ответов
+ 1
Jan Markus what is the ‘_’ after the names? Is it part of the syntax?
21st May 2021, 2:09 AM
Ellison
Ellison - avatar
+ 1
Jan Markus thank you.
21st May 2021, 2:19 AM
Ellison
Ellison - avatar
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:
21st May 2021, 4:20 PM
Ellison
Ellison - avatar