aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-04-26 08:48:25 -0400
committerchirvasitua <stuart-little@users.noreply.github.com>2021-04-26 08:48:25 -0400
commit3743aa2cbefab6331c34fc8c9eb7862312b10ea1 (patch)
treec26b31a7b0b559956d299687269c44cac4bc4372
parent1ff197d81f941c3dd35d77bec8a0326807e8d2b1 (diff)
downloadperlweeklychallenge-club-3743aa2cbefab6331c34fc8c9eb7862312b10ea1.tar.gz
perlweeklychallenge-club-3743aa2cbefab6331c34fc8c9eb7862312b10ea1.tar.bz2
perlweeklychallenge-club-3743aa2cbefab6331c34fc8c9eb7862312b10ea1.zip
1st commit on 110_python
-rwxr-xr-xchallenge-110/stuart-little/python/ch-1.py23
-rwxr-xr-xchallenge-110/stuart-little/python/ch-2.py21
2 files changed, 44 insertions, 0 deletions
diff --git a/challenge-110/stuart-little/python/ch-1.py b/challenge-110/stuart-little/python/ch-1.py
new file mode 100755
index 0000000000..1287c19b6f
--- /dev/null
+++ b/challenge-110/stuart-little/python/ch-1.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+
+# run <script> <path-to-file or nothing>
+# defaults to challenge sample if no file is entered
+
+import re
+import sys
+
+if (len(sys.argv)>1):
+ with open(sys.argv[1]) as f:
+ data=f.read()
+else:
+ data="""
+0044 1148820341
+ +44 1148820341
+ 44-11-4882-0341
+(44) 1148820341
+ 00 1148820341
+"""
+rgx=re.compile(r'((?:\+\d{2}|\(\d{2}\)|\d{4})\s+\d{10})')
+nrs=re.findall(rgx,data)
+for nr in nrs:
+ print(nr)
diff --git a/challenge-110/stuart-little/python/ch-2.py b/challenge-110/stuart-little/python/ch-2.py
new file mode 100755
index 0000000000..7c92a1ae8d
--- /dev/null
+++ b/challenge-110/stuart-little/python/ch-2.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+
+# run <script> <path-to-file or nothing>
+# defaults to challenge sample if no file is entered
+
+import sys
+
+if (len(sys.argv)>1):
+ with open(sys.argv[1]) as f:
+ data=f.read()
+else:
+ data="""name,age,sex
+Mohammad,45,m
+Joe,20,m
+Julie,35,f
+Cristina,10,f
+"""
+
+transpLines = list(map(lambda x: ','.join(x), list(zip(*list(map(lambda x: x.split(','),data.splitlines()))))))
+for ln in transpLines:
+ print(ln)