BWeave Ramblings, maybe, when I get around to it.

Python List Comprehensions

Python List Comprehensions are p rad. They go like this:

variable = [out_exp for out_exp in input_list if out_exp == 2]

Here’s a fun example taken from Exercism.io’s Python track:

number = 105
rain_drops = {3: "Pling", 5: "Plang", 7: "Plong"}
rain_sounds = [sound for value, sound in raindrops.items() if number % value == 0]
# rain_sounds: "PlingPlangPlong"