aboutsummaryrefslogtreecommitdiff
path: root/challenge-096/abigail/python
diff options
context:
space:
mode:
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])