From 5e3d5d115672cabb9dd76d9c00c56892649555d5 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Wed, 1 Dec 2021 02:49:15 +0100 Subject: [PATCH] streamline input getting --- aoc.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/aoc.py b/aoc.py index cf90202..af9ecb9 100644 --- a/aoc.py +++ b/aoc.py @@ -1,6 +1,6 @@ import os import tools -from typing import List, Any, Type +from typing import List, Any, Type, Union BASE_PATH = tools.get_script_dir() INPUTS_PATH = os.path.join(BASE_PATH, 'inputs') @@ -59,6 +59,12 @@ class AOCDay: self.input = live_input return True + def getInput(self) -> Union[str, List]: + if len(self.input) == 1: + return self.input[0] + else: + return self.input + def getInputListAsType(self, return_type: Type) -> List: """ get input as list casted to return_type, each line representing one list entry @@ -90,19 +96,6 @@ class AOCDay: return return_array - def getInputAs2DArray(self, return_type: Type = None) -> List: - """ - get input for day x as 2d-array (a[line][pos]) - """ - if return_type is None: - return self.input # strings already act like a list - else: - return_array = [] - for line in self.input: - return_array.append([return_type(i) for i in line]) - - return return_array - def getInputAsArraySplit(self, split_char: str = ',', return_type: Type = None) -> List: """ get input for day x with the lines split by split_char