โ† All lessons

Lesson 41 of 62 ยท 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 first two lessons are free, so you can start there and see how it works.

See the free lessons