Skip to Content
Learn
Python Lists and Dictionaries
More with 'for'

If your list is a jumbled mess, you may need to sort() it.

animals = ["cat", "ant", "bat"] animals.sort() for animal in animals: print animal
  1. First, we create a list called animals with three strings. The strings are not in alphabetical order.
  2. Then, we sort animals into alphabetical order. Note that .sort() modifies the list rather than returning a new list.
  3. Then, for each item in animals, we print that item out as "ant", "bat", "cat" on their own line each.

Instructions

1.

Write a for-loop that iterates over start_list and .append()s each number squared (x ** 2) to square_list.

Then sort square_list!

Folder Icon

Take this course for free

Already have an account?