Get startedGet started for free

Appending to a list

You've been provided with a dictionary called authors, which has information about 20 of the most popular fiction authors in the World. It contains the names of authors as keys and the number of books they've created as values.

You're interested in finding out how many of these authors have made less than 25 books. To do this, you will create a list called authors_below_twenty_five, filling it with author names conditionally based on whether they have created less than 25 books.

This exercise is part of the course

Introduction to Python for Developers

View Course

Exercise instructions

  • Create an empty list called authors_below_twenty_five.
  • Loop through the key and value iterators in the authors dictionary.
  • Inside the for loop, check if value iterator is less than 25.
  • If so, append the author's name to the authors_below_twenty_five list.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create an empty list
authors_below_twenty_five = ____

# Loop through the authors dictionary
for ____, ____ in ____.____():
  
  # Check for values less than 25
  ____:
    
    # Append the author to the list
    authors_below_twenty_five.____(____)
    
print(authors_below_twenty_five)
Edit and Run Code