+ 3

how to find value in dictionary if there is user input??

dic={a:'123',b:'567'} sample dic user=input ('enter:') how to retrieve 123 if user enter a for example

4th Apr 2018, 6:48 PM
KHALIFA EL HARA
KHALIFA EL HARA - avatar
4 ответов
+ 3
Thank you Jan and Markus. I wrote print(dic.get(user)), it didn't work out.
4th Apr 2018, 9:27 PM
KHALIFA EL HARA
KHALIFA EL HARA - avatar
+ 2
Actually, i m planing to use loop and dic is a lot of strings.
4th Apr 2018, 9:29 PM
KHALIFA EL HARA
KHALIFA EL HARA - avatar
+ 1
print(dic['a']) Also, you might want to make the dictionary keys into strings,
4th Apr 2018, 7:02 PM
Markus Kaleton
Markus Kaleton - avatar
0
you shouldnt use a loop to do simple stuff ex. if you only need single values, Jans first example is the best way to go.
4th Apr 2018, 10:26 PM
Markus Kaleton
Markus Kaleton - avatar