×

python · level 2 · unit 2 · lesson 2

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

hands back a tidy copy of your list.

sorted(scores) gives you a new list in order: smallest first for numbers, A to Z for words. The original list is left exactly as it was.

Add reverse=True for order, biggest first, which is how a leaderboard puts the winner on top. reverse=True is a : you name the parameter and give it a value.

Words are sorted letter by letter, and every capital comes before every small letter. A list also has a .sort() method, which sorts the list itself instead of making a copy.

scores = [42, 97, 63, 85]
print(sorted(scores))
print(sorted(scores, reverse=True))
print(scores)
names = ["Zoe", "amy", "Bea"]
print(sorted(names))

Because capitals come first, "Zoe" sorts before "amy".