How to check if two lines have intersection in python?

For example, a = "abcdefg", b = "krtol", they have no intersection, c = "hflsfjg", then a and c have interoperational interaction.
What is the easiest way to verify this? just need True or False result

+4
source share
2 answers
def hasIntersection(a, b): return not set(a).isdisjoint(b) 
+10
source

You can use the built-in set class:

 a = set("abcdefg") b = set("krtol") c = set("hflsfjg") if a.intersection(b): # or simply a & b pass 
+4
source

All Articles