Syntax

Python Sort a List Syntax

In Python, sort a list: returns a new sorted list — sorted(items, key=len, reverse=True)

Quick Answer

Syntax
sorted(items, key=len, reverse=True)
PythonSyntax

Sort a List

Code example
sorted(items, key=len, reverse=True)

Returns a new sorted list.

Learn More

How to sort a list in Python

  1. Open your Python file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Python Sort a List Syntax

Use sorted(items, key=len, reverse=True).

Related Syntax References

Frequently asked questions

What is the Python syntax for sort a list?

Use this pattern: sorted(items, key=len, reverse=True)

Can I copy this Python code example?

Yes. Use Copy code and adapt the example to your program.

Is this Python syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify