sorted()
noun
say it: “SOR-tid” /ˈsɔrtɪd/
A built-in Python function that gives back a new list in order and leaves the original as it was.
What does sorted() do?
sorted() gives back a new, sorted list and leaves the original alone.
names = ["Zoe", "Adam", "Mia"]
print(sorted(names)) # ['Adam', 'Mia', 'Zoe']
print(names) # ['Zoe', 'Adam', 'Mia']
In a sentence
- “sorted() gave the names in alphabetical order while the sign-up list kept its order.”
- “The report used sorted() with key=len to list words from shortest to longest.”
Level: Apprentice · More Python terms at this level
Updated