Finding a tuple in a tuple

Jussi Salmela tiedon_jano at hotmail.com
Thu Feb 22 07:20:44 EST 2007


bg_ie at yahoo.com kirjoitti:
> Hi,
> 
> Lists say I have the following tuple -
> 
> t1 = ("ONE","THREE","SIX")
> 
> and then the following tuples -
> 
> t2 = ("ONE","TWO","THREE")
> 
> t3 = ("TWO","FOUR","FIVE","SIX")
> 
> t4 = ("TWO",)
> 
> t5 = ("TWO","FIVE")
> 
> What I want to do is return true if any member of tuple t1 is found in
> the remaining tuples.
> 
> Therefore -
> 
> 2) ("ONE","TWO","THREE") : TRUE
> 
> 3) ("TWO","FOUR","FIVE","SIX") : TRUE
> 
> 4) ("TWO",) FALSE
> 
> 5) ("TWO","FIVE")
> 
> How do I do this?
> 
> Cheers,
> 
> Barry.
> 

Another variation of the theme:

#====================
for t in (t2, t3, t4, t5):
     for x in t1:
         if x in t:
             print True
             break
     else: print False
#====================


HTH,
Jussi



More information about the Python-list mailing list