Skip to content

Skip Sorted List Construction

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

Sourcery refactoring id: skip-sorted-list-construction

Section titled “Sourcery refactoring id: skip-sorted-list-construction”

Removes an unnecessary intermediate construction call for a sorted list, in favour of the sorted builtin.

pies = list(pie_generator())
pies.sort()
pies = sorted(pie_generator())

It’s unnecessary to construct an intermediate list when sorting a generator, as the sorted builtin returns a list.