diff options
| author | Abigail <abigail@abigail.be> | 2021-04-30 22:47:38 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-04-30 22:47:38 +0200 |
| commit | 8bcf6551730487cf51398a844b726d6fed93f647 (patch) | |
| tree | c7064e1697fd05cd9a4681d82c425043858fc561 | |
| parent | c390ee8b510a56f5211dd3cca21b1934e3cdca04 (diff) | |
| download | perlweeklychallenge-club-8bcf6551730487cf51398a844b726d6fed93f647.tar.gz perlweeklychallenge-club-8bcf6551730487cf51398a844b726d6fed93f647.tar.bz2 perlweeklychallenge-club-8bcf6551730487cf51398a844b726d6fed93f647.zip | |
Python solution for week 110, part 2
| -rw-r--r-- | challenge-110/abigail/README.md | 1 | ||||
| -rw-r--r-- | challenge-110/abigail/python/ch-2.py | 30 |
2 files changed, 31 insertions, 0 deletions
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) |
