Lesson 14 of 18 · about 15 minutes
Comprehensions and Generators ⚡
Comprehensions and Generators ⚡ Comprehensions build collections in a single readable line. squares = [n * n for n in range(10)] evens = [n for n in range(20) if n % 2 == 0] lengths = {word: len(word) for word in ["hi", "hello"]} unique_initials = {name[0]…
This lesson is part of Pythonaut Pro. The full Launchpad track is free forever, so you can start there and come back.