37 lines
813 B
Python
37 lines
813 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from time import time
|
|
import re
|
|
|
|
start_time = time()
|
|
|
|
# file = "./input.txt"
|
|
file = "./ex-small.txt"
|
|
|
|
|
|
# file = "./ex-big.txt"
|
|
|
|
|
|
def read_and_parse(input_file: str) -> tuple[dict[str:int], list[tuple[str, str, str, str]]]:
|
|
result_dict = {}
|
|
with open(input_file, 'r') as d:
|
|
datei = d.read()
|
|
pat_dict = r'(.+)\: +(\d)'
|
|
pat_list = r'(.+) +(.+) +(.+) +\-\> +(.+)'
|
|
match_d = re.findall(pat_dict, datei)
|
|
# print(match_d)
|
|
for d in match_d:
|
|
result_dict[d[0]] = int(d[1])
|
|
match_l = re.findall(pat_list, datei)
|
|
# print(match_l)
|
|
return result_dict, match_l
|
|
|
|
|
|
if __name__ == "__main__":
|
|
in_dict, in_list = read_and_parse(file)
|
|
print(in_dict)
|
|
print(in_list)
|
|
|
|
print(f'Runtime: {time() - start_time:.2f} s')
|