Levenshtein Distance Sort FIXED by rolf

import sys
def l(a):
 R=range(99)
 for u in a:
\x09S=R;R=[R[0]+1]
\x09for x in I[0]:y,z=S[:2];R+=[min(y+(x!=u),z+1,R[-1]+1)];S=S[1:]
 return R[-1]
I=sys.stdin.readlines() 
for x in sorted(I,key=l):print x,

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

download

return to the top page