aboutsummaryrefslogtreecommitdiff
path: root/challenge-110/cristian-heredia/python
diff options
context:
space:
mode:
authorCris-HD <crisn7@hotmail.com>2021-05-02 19:51:28 +0200
committerCris-HD <crisn7@hotmail.com>2021-05-02 19:51:28 +0200
commit270a7de8aed488e9cffd080da540d734e7d98b1d (patch)
tree36a0f2f3b286ebb65f3d45c4912498e2f046b119 /challenge-110/cristian-heredia/python
parent597cbad831165a61d1c856fae84e97ee2dc27078 (diff)
downloadperlweeklychallenge-club-270a7de8aed488e9cffd080da540d734e7d98b1d.tar.gz
perlweeklychallenge-club-270a7de8aed488e9cffd080da540d734e7d98b1d.tar.bz2
perlweeklychallenge-club-270a7de8aed488e9cffd080da540d734e7d98b1d.zip
Added challenge 110 solution
Diffstat (limited to 'challenge-110/cristian-heredia/python')
-rw-r--r--challenge-110/cristian-heredia/python/ch_1.py54
-rw-r--r--challenge-110/cristian-heredia/python/ch_2.py31
2 files changed, 85 insertions, 0 deletions
diff --git a/challenge-110/cristian-heredia/python/ch_1.py b/challenge-110/cristian-heredia/python/ch_1.py
new file mode 100644
index 0000000000..fff5965db1
--- /dev/null
+++ b/challenge-110/cristian-heredia/python/ch_1.py
@@ -0,0 +1,54 @@
+'''
+ Task #1 › 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
+'''
+
+import re
+import os
+
+#Variables
+text = """
+0044 1148820341
++44 1148820341
+44-11-4882-0341
+(44) 1148820341
+00 1148820341
+"""
+
+def askFileName():
+ file_name = input("Please, introduce the name of the file\n")
+
+ #We check that the file exists, if not, the file is created with a specific text
+ if (os.path.isfile(file_name) == False):
+ f = open(file_name, 'w')
+ f.write(str(text))
+ f.close()
+ print ("Output:")
+ readTelf(file_name)
+
+def readTelf(file_name):
+ with open(file_name, 'r') as my_file:
+ for row in my_file:
+ if (re.match(r"\+\d{2}\s\d{10}", row)) or (re.match(r"\(\d{2}\)\s\d{10}", row)) or (re.match(r"\d{4}\s\d{10}", row)):
+ print(row,end="")
+
+askFileName() \ No newline at end of file
diff --git a/challenge-110/cristian-heredia/python/ch_2.py b/challenge-110/cristian-heredia/python/ch_2.py
new file mode 100644
index 0000000000..fdf11429fc
--- /dev/null
+++ b/challenge-110/cristian-heredia/python/ch_2.py
@@ -0,0 +1,31 @@
+'''
+ TASK #2 › 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
+'''
+
+import csv
+import sys
+
+
+with open(sys.argv[1], 'r') as my_file:
+ data_CSV = csv.reader(my_file)
+ list_CSV = list(data_CSV)
+result = map(list, zip(*list_CSV))
+for r in result:
+ for j in r:
+ print(j, end= ', ')
+ print() \ No newline at end of file