S
Seoffix.com
Sign In Get Pro Membership

DSA & Problem Solving

Sorting

Intermediate Python 35 XP

Sorting

sorted() returns a new sorted list, and key chooses what to compare.

Example

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

Your task

Sort names by length, shortest first, and print the list.

Hints

  1. sorted(names, key=len)

Check your understanding

Answer every question to pass.
1. What does sorted() return?

Your answer

This lesson is checked against the lesson rules. Your code is never run on our servers.

AI Code Explainer & Translator

Runs without any outside service.
 
Mark Complete & Earn XP
Earn 35 XP after you pass the quiz. Finish every lesson in the track to earn its certificate.
Sign in to earn XP

DSA & Problem Solving

Lessons in this track
Questions about this lesson? Ask the Coding & Web Dev squad. Discuss in Community