In addition to 13.New Entries


#1



https://www.codecademy.com/en/courses/python-beginner-en-pwmb1/2/2?curriculum_id=4f89dab3d788890003000096



I wonder how it works if I put a list inside the dictionary.

so I tried the code on line 9~11, and it came out 'D' : 12 , 'i' : 13 , 'r' : 14.

but I dont know why.


Replace this line with your code.


#2

When you do this..

menu["Drink"[0]] = 12 -- > It reduces to menu["D"] = 12 --> it reduces to -> "D" : 12
menu["Drink"[1]] = 14-- > It reduces tomenu["r"] = 14--> it reduces to ->"r" : 14
menu["Drink"[2]] = 13 -- > It reduces to menu["i"] = 13 --> it reduces to -> "i" : 13

You can see in your dictionary,You have "D" : 12 , "r" : 14 and "i" : 13 as key: value pairs.
"Drink" is a string..
so..we can access its individual character using index operator( []).

"Drink"[0] --> "D"
"Drink"[1] --> "r"
"Drink"[2] --> "i"

#3

oohs that's so amazing ! thanks


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.