lwant's picture
Add CSV utility function for reading as dictionaries and introduce experimentation data file
5072271
raw
history blame contribute delete
492 Bytes
import csv
import re
def extract_pattern(pattern: str, text: str) -> str | None:
matches = re.findall(pattern, text)
if matches:
extracted = matches[-1]
return extracted
else:
return None
def read_csv_to_dicts(file_path) -> list[dict]:
with open(file_path, mode='r', newline='', encoding='utf-8') as csvfile:
csv_reader = csv.DictReader(csvfile)
rows = []
for row in csv_reader:
rows.append(row)
return rows