diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-04-26 17:08:53 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-26 17:08:53 +0100 |
| commit | c453c35d35661e59eb2f312dde1165e0acc09d4c (patch) | |
| tree | 4092b847da6bd57c82a3bd4e8b84f978d0851d55 | |
| parent | f28c7552a8cf83175f8da6a5badd4ae153af6a08 (diff) | |
| parent | 3743aa2cbefab6331c34fc8c9eb7862312b10ea1 (diff) | |
| download | perlweeklychallenge-club-c453c35d35661e59eb2f312dde1165e0acc09d4c.tar.gz perlweeklychallenge-club-c453c35d35661e59eb2f312dde1165e0acc09d4c.tar.bz2 perlweeklychallenge-club-c453c35d35661e59eb2f312dde1165e0acc09d4c.zip | |
Merge pull request #3965 from stuart-little/stuart-little_110_python
1st commit on 110_python
| -rwxr-xr-x | challenge-110/stuart-little/python/ch-1.py | 23 | ||||
| -rwxr-xr-x | challenge-110/stuart-little/python/ch-2.py | 21 |
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) |
