aboutsummaryrefslogtreecommitdiff
path: root/challenge-110/lubos-kolouch/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-110/lubos-kolouch/python')
-rw-r--r--challenge-110/lubos-kolouch/python/ch-1.py20
-rw-r--r--challenge-110/lubos-kolouch/python/ch-2.py21
2 files changed, 41 insertions, 0 deletions
diff --git a/challenge-110/lubos-kolouch/python/ch-1.py b/challenge-110/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..c852da1766
--- /dev/null
+++ b/challenge-110/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import re
+
+
+def valid_phone_numbers(filename):
+ with open(filename, 'r') as f:
+ contents = f.readlines()
+
+ valid_numbers = []
+
+ for line in contents:
+ if re.match(r"^(\+|\()?(\d{2,4})\)?(\s|\-)?\d{2,4}(\s|\-)?\d{2,4}(\s|\-)?\d{2,4}$", line.strip()):
+ valid_numbers.append(line.strip())
+
+ return valid_numbers
+
+
+print(valid_phone_numbers('phone_numbers.txt'))
diff --git a/challenge-110/lubos-kolouch/python/ch-2.py b/challenge-110/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..7837aca6d7
--- /dev/null
+++ b/challenge-110/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+def transpose_file(filename):
+ with open(filename, 'r') as f:
+ lines = f.readlines()
+
+ # Split each line into a list of fields
+ lines = [line.strip().split(',') for line in lines]
+
+ # Use zip() to transpose rows to columns
+ transposed = zip(*lines)
+
+ # Join the fields back together and write to a new file
+ with open('transposed_' + filename, 'w') as f:
+ for row in transposed:
+ f.write(','.join(row))
+ f.write('\n')
+
+
+transpose_file('input.txt')