aboutsummaryrefslogtreecommitdiff
path: root/challenge-096/abigail/python
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-01-19 22:48:57 +0000
committerGitHub <noreply@github.com>2021-01-19 22:48:57 +0000
commitab1d7622d09b4faf8f377bba91ed7e2661d8b372 (patch)
tree637f36f168ac488eca0e51e6ac1e016a28f49d71 /challenge-096/abigail/python
parentd177c88a00c0d97ab0e3b61fb827c5fe8ac210a5 (diff)
parent053b0ef31a9cddae0cbd792ad539b2d68876538c (diff)
downloadperlweeklychallenge-club-ab1d7622d09b4faf8f377bba91ed7e2661d8b372.tar.gz
perlweeklychallenge-club-ab1d7622d09b4faf8f377bba91ed7e2661d8b372.tar.bz2
perlweeklychallenge-club-ab1d7622d09b4faf8f377bba91ed7e2661d8b372.zip
Merge pull request #3323 from Abigail/abigail/week-096
Abigail/week 096
Diffstat (limited to 'challenge-096/abigail/python')
-rw-r--r--challenge-096/abigail/python/ch-1.py6
-rw-r--r--challenge-096/abigail/python/ch-2.py21
2 files changed, 27 insertions, 0 deletions
diff --git a/challenge-096/abigail/python/ch-1.py b/challenge-096/abigail/python/ch-1.py
new file mode 100644
index 0000000000..ddc34e2633
--- /dev/null
+++ b/challenge-096/abigail/python/ch-1.py
@@ -0,0 +1,6 @@
+import fileinput
+
+for line in fileinput . input ():
+ words = line . strip () . split ()
+ words . reverse ()
+ print (" " . join (words))
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])