aboutsummaryrefslogtreecommitdiff
path: root/challenge-110/lubos-kolouch/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-110/lubos-kolouch/python/ch-2.py')
-rw-r--r--challenge-110/lubos-kolouch/python/ch-2.py21
1 files changed, 21 insertions, 0 deletions
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')