Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Loops

Exercise 1 integers

Create a list of integers from 1 to 10, and use a for loop with yield to create a new list containing the squares of each integer.

Exercise 2 string lengths

Create a list of strings, and use a for loop with yield to create a new list containing the lengths of each string.

Exercise 3 evens

Create a list of integers, and use a for loop with yield to create a new list containing only the even integers.

Exercise 4 tuples

Create a list of tuples containing a name and an age, and use a for loop with yield to create a new list containing only the names of people who are under 30 years old.

Exercise 5 string contains

Create a list of strings, and use a for loop with yield to create a new list containing only the strings that contain the letter "a".