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