1.py 616 B

1234567891011121314151617181920212223
  1. def validate(entry, required_fields):
  2. for field in required_fields:
  3. if field not in entry:
  4. return False
  5. return True
  6. entries = []
  7. entry = {}
  8. with open("input") as f:
  9. for line in f:
  10. line = line.strip()
  11. if not line:
  12. entries.append(entry)
  13. entry = {}
  14. else:
  15. for field in line.split(" "):
  16. key, value = field.split(":")
  17. entry[key] = value
  18. entries.append(entry)
  19. required = ['byr', 'iyr', 'eyr', 'hgt', 'hcl', 'ecl', 'pid']
  20. print(list(map(lambda x: validate(x, required), entries)).count(True))