From 8029e50d830b3733e7e834a40b90f3eda4240b27 Mon Sep 17 00:00:00 2001 From: Vasile-Hij Date: Fri, 26 May 2023 11:12:33 +0300 Subject: [PATCH] refactor-day-05 resolves #7 --- common/util.py | 9 +++++++-- py/22/day05.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/common/util.py b/common/util.py index bc8950d..9e965f5 100644 --- a/common/util.py +++ b/common/util.py @@ -22,8 +22,8 @@ def helper_base(source: str, year: str, functions: callable = str, display: int display_items('Raw input', day_text.splitlines(), display) data = make_tuple(parser_function, segmentation) - if parser_function != str or parser_function != lines: - display_items('Parsed file', data, display) + #if parser_function != str or parser_function != lines: + display_items('Parsed file', data, display) return data @@ -125,3 +125,8 @@ def each_first_item(data: str): def each_item(data: str): return [item for item in data] + +def strings_per_line(data): + _data = paragraph(data) + return [[item for item in line.split('\n') if item] for line in _data if line][0] + diff --git a/py/22/day05.py b/py/22/day05.py index de0878f..cbc72c8 100644 --- a/py/22/day05.py +++ b/py/22/day05.py @@ -4,7 +4,7 @@ def start_day(): name = '--- Day 5: Supply Stacks ---' - parser_function = 'each_item' + parser_function = 'strings_per_line' display_lines_or_paragraph = 'paragraph' return name, parser_function, display_lines_or_paragraph