+ 2

How can I check if there is an element in a dictionary without using dicc.values?

for example: dicc={key:("mi", "car")} is ("mi", "car") in dicc??

24th Jan 2017, 6:55 PM
MIGUEL GARCÍA GÓMEZ
MIGUEL GARCÍA GÓMEZ - avatar
13 odpowiedzi
+ 13
@Leshark it has! ~_~
24th Jan 2017, 7:17 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 12
(@Alex check out other people posts too, they usually have "-3" votes, maybe someone created 3 fake accounts to troll……)
24th Jan 2017, 7:12 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 1
The second one then
24th Jan 2017, 7:00 PM
MIGUEL GARCÍA GÓMEZ
MIGUEL GARCÍA GÓMEZ - avatar
+ 1
Thank you
24th Jan 2017, 7:15 PM
MIGUEL GARCÍA GÓMEZ
MIGUEL GARCÍA GÓMEZ - avatar
0
Obviously that was an example, i want to know how can I write that in python. I mean how can i check if a tuple is a value in a dictionary
24th Jan 2017, 7:06 PM
MIGUEL GARCÍA GÓMEZ
MIGUEL GARCÍA GÓMEZ - avatar
0
Why the down-votes, if you want to check for tuples just do >>> d = {(1, 2): ('A', 'B'), (3, 4): ('C', 'D')} >>> (1, 2) in d True >>> d[(1, 2)] ('A', 'B') >>> d[(1, 2)][0] 'A'
24th Jan 2017, 7:09 PM
Alex
Alex - avatar
- 1
Alex, what are you doing? Stop spamming your not correct answers.
24th Jan 2017, 7:13 PM
Leshark
Leshark - avatar
- 1
@ValentinHacker, seem's kinda pointless to do that in a Q&A section :/ @Leshark, it's not incorrect it's perfectly valid to check for tuples that way too, don't downvote someone becuase they offered a different way to do it.
24th Jan 2017, 7:17 PM
Alex
Alex - avatar
- 2
@Alex, look at your answer and think a bit. You check is particular case, and my is not particular @ValentinHacker, where? I can't find it in my ios app(
24th Jan 2017, 7:19 PM
Leshark
Leshark - avatar
- 3
Yes it is in your dictionary, you created a tuple.
24th Jan 2017, 7:02 PM
Leshark
Leshark - avatar
- 3
Iterate dictionary values and use type() fucntion So: type(dict[key]) == tuple #True P.S. JEES, ALEX STOP, IT IS INCORRECT!!!
24th Jan 2017, 7:08 PM
Leshark
Leshark - avatar
- 3
This app need a report function:(
24th Jan 2017, 7:16 PM
Leshark
Leshark - avatar
- 4
U have 2 different questions in main and example part. What to answer?
24th Jan 2017, 6:59 PM
Leshark
Leshark - avatar