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
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course