diff options
| author | Abigail <abigail@abigail.be> | 2021-01-19 13:42:51 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-01-19 13:42:51 +0100 |
| commit | b3fd5101407177b4d9a8e2d41b3e063269cee6ba (patch) | |
| tree | b89a144816f107e483fb820a901a50f5020fe59b | |
| parent | 244e676bc1ed3e802597168c002398615fbcb062 (diff) | |
| download | perlweeklychallenge-club-b3fd5101407177b4d9a8e2d41b3e063269cee6ba.tar.gz perlweeklychallenge-club-b3fd5101407177b4d9a8e2d41b3e063269cee6ba.tar.bz2 perlweeklychallenge-club-b3fd5101407177b4d9a8e2d41b3e063269cee6ba.zip | |
Python solution for week 96, part 2.
| -rw-r--r-- | challenge-096/abigail/python/ch-2.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/challenge-096/abigail/python/ch-2.py b/challenge-096/abigail/python/ch-2.py new file mode 100644 index 0000000000..deaeff14cf --- /dev/null +++ b/challenge-096/abigail/python/ch-2.py @@ -0,0 +1,21 @@ +import fileinput + +def LevenshteinDistance (first, second): + n = len (first) + m = len (second) + distance = [] + for i in range (n + 1): + distance . append ([]) + for j in range (m + 1): + distance [i] . append (i + j if i == 0 or j == 0 else + min (distance [i - 1] [j] + 1, + distance [i] [j - 1] + 1, + distance [i - 1] [j - 1] + + (0 if first [i - 1] == + second [j - 1] else 1))) + return distance [n] [m] + + +for line in fileinput . input (): + words = line . strip () . split () + print LevenshteinDistance (words [0], words [1]) |
