Finding a tuple in a tuple
Paul Rubin
http
Thu Feb 22 04:05:10 EST 2007
bg_ie at yahoo.com writes:
> Lists say I have the following tuple -
> t1 = ("ONE","THREE","SIX")
> 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.
Convert them into sets and use the set intersection (&) operator,
then convert to bool to represent whether the intersection is empty.
print bool(set(t1) & set(t2))
print bool(set(t1) & set(t3))
print bool(set(t1) & set(t4))
print bool(set(t1) & set(t5))
More information about the Python-list
mailing list