I would like to have a python function that given the list
mystrings = ['abcde', 'abcdf', 'abcef', 'abcnn']
returns the string 'abc', i.e., the longest piece contained by all the elements in the list. I have a solution which just loops through the slices of mystring[0]
, and compares it to the rest, and breaks out of the loop, whenever the first unmatching substring is found. However, I suspect that there must be a more efficient, elegant, and pythonic way of doing this.
Could someone point out how to do this properly?