with open("input") as f: puzzle_input = [n.strip() for n in f.readlines()] nice_words = 0 def has_three_or_more_vowels(word): vowels = 0 for char in word: if char in "aeiou": vowels += 1 if vowels >= 3: return True return False def has_letter_twice_in_a_row(word): last = word[0] for char in word[1:]: if last == char: return True last = char return False def contains_bad_string(word): BAD_STRINGS = ["ab", "cd", "pq", "xy"] for bad_string in BAD_STRINGS: if bad_string in word: return True return False def is_nice_word(word): return ( has_three_or_more_vowels(word) and has_letter_twice_in_a_row(word) and not contains_bad_string(word) ) for word in puzzle_input: if is_nice_word(word): nice_words += 1 print(nice_words)