aoc.splitline(): allow return fields to have different types
This commit is contained in:
parent
b8e54f51f5
commit
ef0da77133
4
aoc.py
4
aoc.py
@ -96,7 +96,7 @@ class AOCDay:
|
|||||||
|
|
||||||
return return_array
|
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
|
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
|
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:
|
if return_type is None:
|
||||||
return line
|
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:
|
else:
|
||||||
return [return_type(i) for i in line]
|
return [return_type(i) for i in line]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user