SyntaxFix
Write A Post
Hire A Developer
Questions
Try:
import itertools as it ''.join(el[0] for el in it.takewhile(lambda t: t[0] == t[1], zip(string1, string2)))
It does the comparison from the beginning of both strings.