Podría ser así,
#
# @Shell Root
# 2010
#
def getGo(sString1, sString2):
if(len(sString1) < len(sString2)):
return getComparate(sString1, sString2)
elif(len(sString1) > len(sString2)):
return getComparate(sString2, sString1)
elif(len(sString1) == len(sString2)):
return getComparate(sString1, sString2)
else:
return 0;
def getComparate(sString1, sString2):
sCount = 0
sReturn = ""
while( sCount < len(sString1)):
if(sString1[sCount] == sString2[sCount]):
sReturn += sString1[sCount]
else:
break
sCount += 1
return sReturn
print getGo("metafisica", "metafora")
print getGo("alejandro", "alejandra")
print getGo("alex", "alexander")
Resultado:alex@shellroot:~/Escritorio$ python PoC.py
metaf
alejandr
alex