How to check if user input exists as values in dictionary if the value is given inside lists | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to check if user input exists as values in dictionary if the value is given inside lists

Values in a dictionary are given inside a list. How to check if an input from the user exists inside the list that is, values of the dictionary?

5th Oct 2020, 9:32 AM
Model Pilot
Model Pilot - avatar
5 Answers
+ 6
Model Pilot , please do a try by yourself before we can help you. put your code in playground and link it here. Thanks. to give you a hint: - take an input from user, and split it to a list - iterate over this list by using a for loop. in each iteration of the for loop, one item from the list will be taken - check if this item is in the dict. the way how you are doing this, depends if you are looking for keys or values in the dict. but i duppose that it should be a key. you can use the membership operator "in" to do this check.
5th Oct 2020, 2:57 PM
Lothar
Lothar - avatar
+ 4
Not quite clear for me. is the input a single number or is input some numbers like : 1,4,0,5 ? can you please just do a sample of the input? Thanks a lot!
5th Oct 2020, 10:46 AM
Lothar
Lothar - avatar
+ 2
input() in dict.values()
5th Oct 2020, 10:03 AM
Seb TheS
Seb TheS - avatar
0
If input is multiple values, how should i check if it exists in a dictionary's value. Values of the dictionary is in a list
5th Oct 2020, 11:04 AM
Model Pilot
Model Pilot - avatar
0
for put in [input(), input(), ...]: put in dict.values()
5th Oct 2020, 12:23 PM
Seb TheS
Seb TheS - avatar