PRACTICE

Sort with a Key

Lesson notes

Your task

Sort ["pear", "fig", "banana"] by length and print the new list.

Expected output
['fig', 'pear', 'banana']
Loading…

OUTPUT

Worked solution
words = ["pear", "fig", "banana"]
print(sorted(words, key=len))

Checks compare printed output, not your approach. Several solutions can be valid.

← Back to courses