aboutsummaryrefslogtreecommitdiff
path: root/challenge-110/abigail/python
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-05-01 01:10:18 +0100
committerGitHub <noreply@github.com>2021-05-01 01:10:18 +0100
commitc86d7cc3cf9f5b4c51d2e6fd99384729a8166418 (patch)
treea8b099562494a78a1aa82ed74c73a40205603a0c /challenge-110/abigail/python
parent111ea37f028e65705520d21e13dcb2735a33ad8a (diff)
parent8bcf6551730487cf51398a844b726d6fed93f647 (diff)
downloadperlweeklychallenge-club-c86d7cc3cf9f5b4c51d2e6fd99384729a8166418.tar.gz
perlweeklychallenge-club-c86d7cc3cf9f5b4c51d2e6fd99384729a8166418.tar.bz2
perlweeklychallenge-club-c86d7cc3cf9f5b4c51d2e6fd99384729a8166418.zip
Merge pull request #3983 from Abigail/abigail/week-110
Abigail/week 110
Diffstat (limited to 'challenge-110/abigail/python')
-rw-r--r--challenge-110/abigail/python/ch-1.py19
-rw-r--r--challenge-110/abigail/python/ch-2.py30
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-110/abigail/python/ch-1.py b/challenge-110/abigail/python/ch-1.py
new file mode 100644
index 0000000000..63e3c8e69e
--- /dev/null
+++ b/challenge-110/abigail/python/ch-1.py
@@ -0,0 +1,19 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-1.py < input-file
+#
+
+import fileinput
+import re
+
+for line in fileinput . input ():
+ plain = re . sub (r'\s+', "", line) # Strip whitespace
+ plain = re . sub (r'^\+', "00", plain) # Replace leading +
+ plain = re . sub (r'^\([0-9][0-9]\)', "0000", plain) # Replace leading (NN)
+ if re . search (r'^[0-9]{14}$', plain): # Chech for 14 digits
+ print (line, end = '')
diff --git a/challenge-110/abigail/python/ch-2.py b/challenge-110/abigail/python/ch-2.py
new file mode 100644
index 0000000000..c5ba11fae6
--- /dev/null
+++ b/challenge-110/abigail/python/ch-2.py
@@ -0,0 +1,30 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-2.py < input-file
+#
+
+import fileinput
+
+outputs = []
+
+#
+# Read input, split on commas, build output strings.
+#
+for line in fileinput . input ():
+ fields = line . rstrip () . split (",")
+ if (len (outputs)):
+ for i in range (len (fields)):
+ outputs [i] = outputs [i] + "," + fields [i]
+ else:
+ outputs . extend (fields)
+
+#
+# Print output lines
+#
+for line in outputs:
+ print (line)