diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2021-05-03 18:31:36 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2021-05-03 18:31:36 +0800 |
| commit | 81252bda7fb7bcc9e9e153a6b3d268ab8c1a38c8 (patch) | |
| tree | e4df369a6349802da33aa6d94b7fe745041a9955 /challenge-110/colin-crain/python | |
| parent | 0142974e5f11adadbaa7ca8d71de9db345318519 (diff) | |
| parent | 0381a39b17ccd040302474f25d3c1cbbef703327 (diff) | |
| download | perlweeklychallenge-club-81252bda7fb7bcc9e9e153a6b3d268ab8c1a38c8.tar.gz perlweeklychallenge-club-81252bda7fb7bcc9e9e153a6b3d268ab8c1a38c8.tar.bz2 perlweeklychallenge-club-81252bda7fb7bcc9e9e153a6b3d268ab8c1a38c8.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-110/colin-crain/python')
| -rw-r--r-- | challenge-110/colin-crain/python/ch-1.py | 42 | ||||
| -rw-r--r-- | challenge-110/colin-crain/python/ch-2.py | 52 |
2 files changed, 94 insertions, 0 deletions
diff --git a/challenge-110/colin-crain/python/ch-1.py b/challenge-110/colin-crain/python/ch-1.py new file mode 100644 index 0000000000..7c381f1c37 --- /dev/null +++ b/challenge-110/colin-crain/python/ch-1.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3
+#
+#
+# phone-block.py
+#
+# Valid Phone Numbers
+# Submitted by: Mohammad S Anwar
+# You are given a text file.
+#
+# Write a script to display all valid phone numbers in the given text file.
+#
+# Acceptable Phone Number Formats
+# +nn nnnnnnnnnn
+# (nn) nnnnnnnnnn
+# nnnn nnnnnnnnnn
+#
+# Input File
+# 0044 1148820341
+# +44 1148820341
+# 44-11-4882-0341
+# (44) 1148820341
+# 00 1148820341
+#
+# Output
+# 0044 1148820341
+# +44 1148820341
+# (44) 1148820341
+#
+#
+#
+# © 2021 colin crain
+## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
+
+import re
+
+f = open("phone-numbers.txt", "r")
+for line in f:
+ pn = re.search(r"((?:\d{4}|\(\d\d\)|\+\d\d)\s\d{10}(?!\d))", line)
+ if pn != None:
+ print('{0:>16s}'.format(pn.group()))
+
+f.close
diff --git a/challenge-110/colin-crain/python/ch-2.py b/challenge-110/colin-crain/python/ch-2.py new file mode 100644 index 0000000000..d76f2bdaf4 --- /dev/null +++ b/challenge-110/colin-crain/python/ch-2.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3
+#
+# reflect.py
+#
+# Transpose File
+# Submitted by: Mohammad S Anwar
+# You are given a text file.
+#
+# Write a script to transpose the contents of the given file.
+#
+# Input File
+# name,age,sex
+# Mohammad,45,m
+# Joe,20,m
+# Julie,35,f
+# Cristina,10,f
+#
+# Output:
+# name,Mohammad,Joe,Julie,Cristina
+# age,45,20,35,10
+# sex,m,m,f,f
+#
+#
+#
+# © 2021 colin crain
+## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
+
+
+import re
+
+mat = []
+trans = []
+cols = 0
+
+f = open("transpose-data.txt", "r")
+for line in f:
+ row = re.split(",", line.rstrip())
+ mat.append(row)
+ cols = max(cols, len(row))
+f.close
+
+
+trans = [[mat[j][i] for j in range(len(mat))] for i in range(len(mat[0]))]
+
+for i in mat:
+ print( *i )
+
+print()
+
+for i in trans:
+ print( *i )
+
|
