Day 4: Passport Processing

Functions:

blank_line_split(text)

Split the text on a blank line.

parse_passport_entries(text)

Parse the passport entries separated by a blank-line in text.

is_valid(entry)

Verify whether the passport entry is valid.

count_valid(batch)

Count the number of valid passports in the batch.

blank_line_split(text: str) List[str][source]

Split the text on a blank line.

>>> blank_line_split('X\nY\n\nZ')
['X\nY', 'Z']
Ensures
  • len(result) == text.count("nn") + 1

parse_passport_entries(text: str) List[Tuple[str, str]][source]

Parse the passport entries separated by a blank-line in text.

Requires
  • PASSPORT_RE.fullmatch(text)

is_valid(entry: List[Tuple[str, str]]) bool[source]

Verify whether the passport entry is valid.

Ensures
  • result == all(k in dict(entry) for k in _REQUIRED_KEYS)

count_valid(batch: str) int[source]

Count the number of valid passports in the batch.

Requires
  • all(PASSPORT_RE.match(line) for line in blank_line_split(batch))

Ensures
  • result >= 0