From 8bcf6551730487cf51398a844b726d6fed93f647 Mon Sep 17 00:00:00 2001 From: Abigail Date: Fri, 30 Apr 2021 22:47:38 +0200 Subject: Python solution for week 110, part 2 --- challenge-110/abigail/README.md | 1 + challenge-110/abigail/python/ch-2.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 challenge-110/abigail/python/ch-2.py diff --git a/challenge-110/abigail/README.md b/challenge-110/abigail/README.md index e70d4d7b4e..2d2a279ac8 100644 --- a/challenge-110/abigail/README.md +++ b/challenge-110/abigail/README.md @@ -82,6 +82,7 @@ sex,m,m,f,f * [Lua](lua/ch-2.lua) * [Node.js](node/ch-2.js) * [Perl](perl/ch-2.pl) +* [Python](python/ch-2.py) * [Ruby](ruby/ch-2.rb) ### Blog diff --git a/challenge-110/abigail/python/ch-2.py b/challenge-110/abigail/python/ch-2.py new file mode 100644 index 0000000000..c5ba11fae6 --- /dev/null +++ b/challenge-110/abigail/python/ch-2.py @@ -0,0 +1,30 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-2.py < input-file +# + +import fileinput + +outputs = [] + +# +# Read input, split on commas, build output strings. +# +for line in fileinput . input (): + fields = line . rstrip () . split (",") + if (len (outputs)): + for i in range (len (fields)): + outputs [i] = outputs [i] + "," + fields [i] + else: + outputs . extend (fields) + +# +# Print output lines +# +for line in outputs: + print (line) -- cgit