Python program to Check all strings are mutually disjoint
Given a string list, our task is to write a Python Program to check all strings are disjoint from one another.
Input : test_list = [“gfg”, “is”, “bet”]
Output : True
Explanation : No string character repeat in other strings.
Input : test_list = [“gfg”, “is”, “best”]
Output : False
Explanation : s repeats in both “is” and “best”, hence false.
In this, we perform the task of getting common elements using intersection(), and the intersection is performed between all combinations of strings with each other using enumerate() and any() is used to test if any string has any character present in other string.
The original list is : ['gfg', 'is', 'bet'] Are strings mutually disjoint? : True
This problem can be solved by matching the concatenated string lengths and checking for equality of lengths of strings and converted set. Fails in case in which is similar string contains duplicate elements.
The original list is : ['gfg', 'is', 'bet'] Are strings mutually disjoint? : False