re: AoC Day 2: Inventory Management System VIEW POST

TOP OF THREAD FULL DISCUSSION
re: from collections import defaultdict from difflib import SequenceMatcher from operator import itemgetter def similar(a, b): return SequenceMa...
 

Nice! Don’t forget about collections.Counter for part 1! I didn’t know about difflib though. Cool!

 
def part_one():
    word_twice_count = 0
    word_three_times_count = 0

    with open('input.txt', 'r') as input_file:
        for line in input_file:
            line_counter = Counter(line)
            if 2 in line_counter.values():
                word_twice_count += 1
            if 3 in line_counter.values():
                word_three_times_count += 1

    checksum = word_twice_count * word_three_times_count

    print 'checksum is ' + str(checksum)

My edited solution for part one with collections Counter

code of conduct - report abuse