sorted
Performance Patterns

Meaning

Returns a new list containing all items from the iterable in ascending order.

Primary Function

Return a new sorted list from the given iterable.

Communicative Purpose

To obtain a sorted version of a sequence without modifying the original.

Pattern

sorted(<sequence>)

Core Structure

sorted(<sequence>)

Função primária

Return a new sorted list from the given iterable.

Propósito comunicativo

To obtain a sorted version of a sequence without modifying the original.

Situações de gatilho

When a sorted copy of a sequence is needed for display, further processing, or algorithms requiring ordered data.

Contextos

Data processing pipelines, preparing output for users, preparing input for algorithms like binary search.

Padrão

sorted(<sequence>)

Estrutura central

sorted(<sequence>)

Slots de substituição

[seq]

Colocados típicos

  • list
  • dict
  • key
  • reverse

Substituições comuns

  • list.sort()
  • sorted(iterable
  • key=func)
  • heapq.nsmallest

Erros comuns

Assuming sorted modifies the original list; applying sorted to unsortable types; forgetting to assign the return value.

Similar / contraste

similar: list.sort(), heapq.nsmallest; contrasting: unsorted data, max()

Interferências

Confusing sorted() (returns new list) with list.sort() (modifies in-place).

Família do chunk

  • sorted
  • sort
  • list.sort
  • heapq.nsmallest
  • heapq.nlargest

Nuance

Returns a new sorted list; original unchanged; stable sort; works with any iterable; uses Timsort algorithm.

Efeito pragmático

Signals intent to obtain a sorted copy while preserving original data.

Dica de memória

Think of arranging items in order.

Nota

Always returns a new list, regardless of input iterable type.

Tipo de construção: function_callTag de espaçamento: Immediate

Log in to save chunks.