From ef0da77133c033700d150c1c7670e3c286e90839 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Thu, 2 Dec 2021 06:20:34 +0100 Subject: [PATCH] aoc.splitline(): allow return fields to have different types --- aoc.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aoc.py b/aoc.py index af9ecb9..ed2cc38 100644 --- a/aoc.py +++ b/aoc.py @@ -96,7 +96,7 @@ class AOCDay: return return_array - def getInputAsArraySplit(self, split_char: str = ',', return_type: Type = None) -> List: + def getInputAsArraySplit(self, split_char: str = ',', return_type: Union[Type, List[Type]] = None) -> List: """ get input for day x with the lines split by split_char if input has only one line, returns a 1d array with the values @@ -139,5 +139,7 @@ def splitLine(line, split_char=',', return_type=None): if return_type is None: return line + elif isinstance(return_type, list): + return [return_type[x](i) if len(return_type) > x else i for x, i in enumerate(line)] else: return [return_type(i) for i in line]