Files
python-aoc-2020/day04/part1.py
Sebastian Seedorf 4ed5a9a1d1 Day 4
2020-12-05 17:16:10 +01:00

25 lines
538 B
Python

import re
lines = (list(map(lambda a: a.split(':'), x.strip().split())) for x in open("input.txt"))
passport = {}
count = 0
must_have = {'iyr', 'hcl', 'hgt', 'pid', 'ecl', 'eyr', 'byr'}
def check_passport(pp):
valid = len(set(pp).intersection(must_have)) == len(must_have)
if not valid:
return 0
return 1
for line in lines:
if len(line) == 0:
count += check_passport(passport)
passport = {}
for key, val in line:
passport[key] = val
count += check_passport(passport)
print(count)