sorted()

sorted(items) returns a new sorted list from any iterable; items.sort() sorts a list in place and returns None.

In more detail

Both accept key= for a custom ordering and reverse=True for descending order. Writing items = items.sort() loses your list, because sort returns None.

Example

sorted(["pear", "Fig", "apple"], key=str.lower)

Related terms

Taught in

References

Certification courses