+#!/usr/bin/python3
+
+REQUIRED_FIELDS=(('byr', "Birth Year"),('iyr', "Issue Year"),('eyr', "Expiration Year"),('hgt', "Height"),('hcl', "Hair Colour"),('ecl', "Eye Colour"),('pid',"Passport ID"))
+OPTIONAL_FIELDS=(('cid', "Country ID"))
+
+def check_passport(passport_data):
+ print(passport_data)
+ for field in REQUIRED_FIELDS:
+ if field[0] not in passport_data:
+ return False
+ return True
+
+def main():
+ new_passport=False
+ passport_data=dict()
+ valid_passports=0
+ for line in open("input.txt"):
+ if new_passport:
+ if check_passport(passport_data):
+ valid_passports += 1
+ passport_data.clear()
+ line=line.rstrip()
+ if line == '':
+ new_passport=True
+ continue
+ new_passport=False
+ parts=line.split(" ")
+ for part in parts:
+ (key, value) = part.split(":")
+ passport_data[key] = value
+ if not new_passport:
+ if check_passport(passport_data):
+ valid_passports += 1
+ print("Found", valid_passports, "valid passports")
+
+main()