If I have a dict such as:
foo = {('foo', 45):5, ('bar', 34):3}
How can I check against part of that tuple?
if 'foo' in foo: #should be true
pass
if 45 in foo: #also should be true
Or some other syntax.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you don’t know where the value is to be found you can just check the whole pair:
You can also a generators approach (flatten):
That said, probably the best idea is to build your data so you can check this kind of inclussion in O(1) time (a set? a refactored dictionary?)