#!/usr/bin/env python3 import re lines = (x.strip() for x in open("input.txt")) total = 0 regexFirst = re.compile(f"^.*?(\\d)") regexLast = re.compile(f"^.*(\\d)") for line in lines: first = regexFirst.match(line).group(1) last = regexLast.match(line).group(1) total += int(first + last) print(total)