How to check if two strings do not have common characters (mutually disjoint) in Python

1 Answer

0 votes
def are_disjoint(a: str, b: str) -> bool:
    return set(a).isdisjoint(set(b))

print(are_disjoint("abc", "xyz"))     # True  (no common characters)
print(are_disjoint("hello", "world")) # False ('o', 'l' in common)



'''
run:

True
False

'''

 



answered Jan 20 by avibootz
...