2023-12-08 05:57:09 +01:00
|
|
|
import re
|
|
|
|
|
|
|
|
def str_to_single_int(line: str) -> int:
|
|
|
|
line = line.replace(" ", "")
|
2023-12-09 15:56:22 +01:00
|
|
|
r = re.compile(r"-?\d+")
|
2023-12-08 05:57:09 +01:00
|
|
|
for m in r.findall(line):
|
|
|
|
return int(m)
|
|
|
|
raise Exception("No single digit sequence in '{line}'")
|
|
|
|
|
|
|
|
def str_to_int_list(line: str) -> list[int]:
|
2023-12-09 15:56:22 +01:00
|
|
|
r = re.compile(r"-?\d+")
|
2023-12-08 05:57:09 +01:00
|
|
|
return list(map(int, r.findall(line)))
|
|
|
|
|
|
|
|
def str_to_lines_no_empty(text: str) -> list[str]:
|
|
|
|
return list(filter(lambda l: l.strip() != "", text.splitlines()))
|
|
|
|
|
|
|
|
def str_to_lines(text: str) -> list[str]:
|
|
|
|
return list(text.splitlines())
|