[Python Edinburgh] Comparing two Tuples

danjac354 at gmail.com danjac354 at gmail.com
Wed Oct 20 16:12:37 CEST 2010


Off the top of my head:

bool(set(A).intersection(B))

On 20 October 2010 15:03, Dougal Matthews <dougal85 at gmail.com> wrote:
> Random question for you all. I've got a solution but I don't think its that
> intuitive, so I'm curious if there is a neater way.
> What is the best to compare two tuples and see if they contain one or more
> of the same items.
> A = (1,2,3)
> B = (3,4,5)
> C = (6,7,8)
> Where A would match B because they both have 3 and C wouldn't match either.
> if <magic here>:
>     print "One or more item is the same"
> else:
>     print "The tuples don't contain any of the same items"
>
> Dougal
> _______________________________________________
> Edinburgh mailing list
> Edinburgh at python.org
> http://mail.python.org/mailman/listinfo/edinburgh
>
>


More information about the Edinburgh mailing list