aboutsummaryrefslogtreecommitdiff
path: root/challenge-289/roger-bell-west/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-289/roger-bell-west/python/ch-2.py')
-rwxr-xr-xchallenge-289/roger-bell-west/python/ch-2.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-289/roger-bell-west/python/ch-2.py b/challenge-289/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..18f42d7121
--- /dev/null
+++ b/challenge-289/roger-bell-west/python/ch-2.py
@@ -0,0 +1,20 @@
+#! /usr/bin/python3
+
+import fileinput
+import re
+import random
+
+def jumble(a):
+ b = list(a)
+ random.shuffle(b)
+ return "".join(b)
+
+def replace(mt):
+ return mt.group(1) + jumble(mt.group(2)) + mt.group(3)
+
+wordre = re.compile(r"([A-Za-z])([A-Za-z][A-Za-z]+)([A-Za-z])")
+
+for line in fileinput.input():
+ line = line.rstrip()
+ l = re.sub(wordre, replace, line)
+ print(l)