#!/usr/bin/env python3

def parse_data(file):
    data_file = open(file, 'r')
    data = data_file.read().splitlines()

    passports = []
    attr = {}
    for line_number, line in enumerate(data):
        # print(line)
        key_value = line.split(' ')
        # print(key_value)

        for i in key_value:
            # print(i)
            if '' not in key_value:
                key = i.split(':')[0]
                value = i.split(':')[1]
                # print(key)
                # print(value)
                attr[key] = value
        if ('' in key_value) or (line_number == (len(data) - 1)):
                passports.append(attr)
                attr = {}
                continue
    return passports

def check_passport(passport):
    required_field = ['byr','iyr','eyr','hgt','hcl','ecl','pid','cid']
    missing_keys = []
    for key in required_field:
        if key not in passport:
            if key == 'cid':
                continue
            missing_keys.append(key)
    return missing_keys

def main():
    passports = parse_data('data')

    # print("{}".format(passports))
    # print(len(passports))

    number_valid_passports = 0

    for passport in passports:
        missing = check_passport(passport)
        # print(missing)
        # print(len(missing))
        if len(missing) == 0:
            number_valid_passports += 1
    print("# valid passports: {}".format(number_valid_passports))

if __name__== "__main__":
  main()
abf73aae86fa564c10028a0c5762c9818e7de7d8
<mask token>


def main():
    passports = parse_data('data')
    number_valid_passports = 0
    for passport in passports:
        missing = check_passport(passport)
        if len(missing) == 0:
            number_valid_passports += 1
    print('# valid passports: {}'.format(number_valid_passports))


<mask token>

def parse_data(file):
    data_file = open(file, 'r')
    data = data_file.read().splitlines()
    passports = []
    attr = {}
    for line_number, line in enumerate(data):
        key_value = line.split(' ')
        for i in key_value:
            if '' not in key_value:
                key = i.split(':')[0]
                value = i.split(':')[1]
                attr[key] = value
        if '' in key_value or line_number == len(data) - 1:
            passports.append(attr)
            attr = {}
            continue
    return passports


<mask token>


def main():
    passports = parse_data('data')
    number_valid_passports = 0
    for passport in passports:
        missing = check_passport(passport)
        if len(missing) == 0:
            number_valid_passports += 1
    print('# valid passports: {}'.format(number_valid_passports))


<mask token>

def parse_data(file):
    data_file = open(file, 'r')
    data = data_file.read().splitlines()
    passports = []
    attr = {}
    for line_number, line in enumerate(data):
        key_value = line.split(' ')
        for i in key_value:
            if '' not in key_value:
                key = i.split(':')[0]
                value = i.split(':')[1]
                attr[key] = value
        if '' in key_value or line_number == len(data) - 1:
            passports.append(attr)
            attr = {}
            continue
    return passports


def check_passport(passport):
    required_field = ['byr', 'iyr', 'eyr', 'hgt', 'hcl', 'ecl', 'pid', 'cid']
    missing_keys = []
    for key in required_field:
        if key not in passport:
            if key == 'cid':
                continue
            missing_keys.append(key)
    return missing_keys


def main():
    passports = parse_data('data')
    number_valid_passports = 0
    for passport in passports:
        missing = check_passport(passport)
        if len(missing) == 0:
            number_valid_passports += 1
    print('# valid passports: {}'.format(number_valid_passports))


<mask token>

def parse_data(file):
    data_file = open(file, 'r')
    data = data_file.read().splitlines()
    passports = []
    attr = {}
    for line_number, line in enumerate(data):
        key_value = line.split(' ')
        for i in key_value:
            if '' not in key_value:
                key = i.split(':')[0]
                value = i.split(':')[1]
                attr[key] = value
        if '' in key_value or line_number == len(data) - 1:
            passports.append(attr)
            attr = {}
            continue
    return passports


def check_passport(passport):
    required_field = ['byr', 'iyr', 'eyr', 'hgt', 'hcl', 'ecl', 'pid', 'cid']
    missing_keys = []
    for key in required_field:
        if key not in passport:
            if key == 'cid':
                continue
            missing_keys.append(key)
    return missing_keys


def main():
    passports = parse_data('data')
    number_valid_passports = 0
    for passport in passports:
        missing = check_passport(passport)
        if len(missing) == 0:
            number_valid_passports += 1
    print('# valid passports: {}'.format(number_valid_passports))


if __name__ == '__main__':
    main()

#!/usr/bin/env python3

def parse_data(file):
    data_file = open(file, 'r')
    data = data_file.read().splitlines()

    passports = []
    attr = {}
    for line_number, line in enumerate(data):
        # print(line)
        key_value = line.split(' ')
        # print(key_value)

        for i in key_value:
            # print(i)
            if '' not in key_value:
                key = i.split(':')[0]
                value = i.split(':')[1]
                # print(key)
                # print(value)
                attr[key] = value
        if ('' in key_value) or (line_number == (len(data) - 1)):
                passports.append(attr)
                attr = {}
                continue
    return passports

def check_passport(passport):
    required_field = ['byr','iyr','eyr','hgt','hcl','ecl','pid','cid']
    missing_keys = []
    for key in required_field:
        if key not in passport:
            if key == 'cid':
                continue
            missing_keys.append(key)
    return missing_keys

def main():
    passports = parse_data('data')

    # print("{}".format(passports))
    # print(len(passports))

    number_valid_passports = 0

    for passport in passports:
        missing = check_passport(passport)
        # print(missing)
        # print(len(missing))
        if len(missing) == 0:
            number_valid_passports += 1
    print("# valid passports: {}".format(number_valid_passports))

if __name__== "__main__":
  main()