align by common substring by test

def common(a,b):
 l=[]
 for i in range(len(a)):
  j=1
  while b.find(a[i:][:j])!=-1 and j<=len(a):j+=1
  if j>1:l+=[a[i:][:j-1]]
 return sorted(l,cmp,len,1)[0]

a=raw_input()
while 1:
 print a
 b=raw_input()
 c=common(a,b)
 i=a.find(c)
 j=b.find(c)
 b=" "*(i-j)+b
 a=b 

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page