def levenshtein(s, t):
''' From Wikipedia article; Iterative with two matrix rows. '''
if s == t: return 0
elif len(s) == 0: return len(t)
elif len(t) == 0: return len(s)
v0 = [None] * (len(t) + 1)
v1 = [None] * (len(t) + 1)
for i in range(len(v0)):
v0[i] = i
for i in range(len(s)):
v1[0] = i + 1
for j in range(len(t)):
cost = 0 if s[i] == t[j] else 1
v1[j + 1] = min(v1[j] + 1, v0[j + 1] + 1, v0[j] + cost)
for j in range(len(v0)):
v0[j] = v1[j]
return v1[len(t)]
print(levenshtein('голубец', 'конь'))
print(levenshtein('голубец', 'голубцы'))
In [8]: % timeit [i+j for i,j in zip(s[::2], s[1::2])]
100000 loops, best of 3: 2.52 µs per loop
In [9]: % timeit [s[i:i + 2] for i in range(0, len(s), 2)]
100000 loops, best of 3: 3.08 µs per loop