From 2b7dcae3794ff4ff32819db0094152c53e9a568c Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 28 Apr 2021 19:29:23 +0200 Subject: Python solution for week 110, part 1 --- challenge-110/abigail/python/ch-1.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 challenge-110/abigail/python/ch-1.py (limited to 'challenge-110/abigail/python') diff --git a/challenge-110/abigail/python/ch-1.py b/challenge-110/abigail/python/ch-1.py new file mode 100644 index 0000000000..63e3c8e69e --- /dev/null +++ b/challenge-110/abigail/python/ch-1.py @@ -0,0 +1,19 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-1.py < input-file +# + +import fileinput +import re + +for line in fileinput . input (): + plain = re . sub (r'\s+', "", line) # Strip whitespace + plain = re . sub (r'^\+', "00", plain) # Replace leading + + plain = re . sub (r'^\([0-9][0-9]\)', "0000", plain) # Replace leading (NN) + if re . search (r'^[0-9]{14}$', plain): # Chech for 14 digits + print (line, end = '') -- cgit 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/python/ch-2.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 challenge-110/abigail/python/ch-2.py (limited to 'challenge-110/abigail/python') 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