A guard statement is the if condition in a list comprehension. It keeps only iterated elements whose condition evaluates as truthy, producing a filtered collection. section 14.3.1
Keep consonants
vowels = 'aeiou' consonants = ''.join([c for c in string.ascii_lowercase if c not in vowels]) The guard excludes vowels and retains consonants. The same selection can be written with filter(), which applies a function to each iterable element. section 14.3.1
>>> cars = ['blue Honda', 'red Chevy', 'blue Ford']
>>> list(filter(lambda car: car.startswith('blue '), cars))
['blue Honda', 'blue Ford']
Compare guard-based selection with filtering cars by a string prefix; rejected elements simply disappear from the resulting list. section 14.3.1



