Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren0
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?
5 Antworten
+ 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.
+ 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!
+ 2
input() in dict.values()
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
0
for put in [input(), input(), ...]:
put in dict.values()