Levenshtein distance: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 3,527: | Line 3,527: | ||
return costs[b.length()]; |
return costs[b.length()]; |
||
}</lang> |
}</lang> |
||
==={{header|Processing Python mode}}=== |
|||
<lang python>def setup(): |
|||
println(distance("kitten", "sitting")) |
|||
def distance(a, b): |
|||
costs = [] |
|||
for j in range(len(b) + 1): |
|||
costs.append(j) |
|||
for i in range(1, len(a) + 1): |
|||
costs[0] = i |
|||
nw = i - 1 |
|||
for j in range(1, len(b) + 1): |
|||
cj = min(1 + min(costs[j], costs[j - 1]), |
|||
nw if a[i - 1] == b[j - 1] else nw + 1) |
|||
nw = costs[j] |
|||
costs[j] = cj |
|||
return costs[len(b)]</lang> |
|||
=={{header|Prolog}}== |
=={{header|Prolog}}== |