Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I tried to find the available methods but couldn't find it. There is no contains. Should I use index? I just want to know if the item exists, don't need the index of it.

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

You use in.

if element in thetuple:
    #whatever you want to do.
share|improve this answer
    
Thanks, for multiple elements should I do if a in tuple and b in tuple: ? –  Joan Venge Jul 29 '13 at 9:20
    
Yes. If you have a lot of elements you might consider using sets instead, where you can do union, difference and intersection operations. –  Lennart Regebro Jul 29 '13 at 9:23
    
Thanks, actually the API I am using is returning a tuple, that's why I was using that. Should I convert it to a set? –  Joan Venge Jul 29 '13 at 9:23
    
@JoanVenge: If you want it to be a set, yes. –  Lennart Regebro Jul 29 '13 at 9:24
    
Thanks will do. I just didn't want to change the data types too much because it's gonna get called 10000s of times every frame. –  Joan Venge Jul 29 '13 at 9:29
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.