Skip to content
Advertisement

Identifying common elements in a list of words

I have list of words in a column where I need to find common elements. For example, list contains words such as,

sinazz31 sinazz12 45sinazz sinazz_84

As you can see, the common element is “sinazz”. Is there a way to develop an algorithm in Python to identify such common elements? If the length of the words are less than 4, the words can be ignored.

Advertisement

Answer

You could search for substrings contained in all of the source strings. Starting with the length of the shortest string and going down from there:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement