#!/usr/bin/python3 required_fields = { "byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid",} valid = 0 with open("input") as fh: all_data = fh.read() passport_strings = all_data.split("\n\n") for ps in passport_strings: fields = ps.split() passport = {} for f in fields: k, v = f.split(":") passport[k] = v if required_fields - set(passport.keys()) == set(): valid += 1 print(valid)