AI engineering glossary · Python core

What is sorted?

sorted: A built-in function that returns a new sorted list from any iterable, leaving the original untouched. It accepts a key function to choose what to sort by and reverse=True for descending order. The sort is stable.

Level: beginnerTopic: Python core

sorted: an example

sorted([3, 1, 2]) gives [1, 2, 3]; sorted(names, key=len, reverse=True) puts the longest names first.

Related terms

More Python core terms

Where you learn it

sorted is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.