frozenset(; ) | frozenset
Built-in Data Structures

Meaning

Creates an immutable union of two frozensets using the bitwise OR operator, producing a new frozenset containing all distinct elements from both operands.

Primary Function

Set union

Communicative Purpose

Provides a concise way to compute the union of two frozensets without converting to mutable sets.

Pattern

frozenset(iterable1) | frozenset(iterable2)

Core Structure

frozenset(...) | frozenset(...)

Função primária

Set union

Propósito comunicativo

Provides a concise way to compute the union of two frozensets without converting to mutable sets.

Situações de gatilho

When you need to combine two frozensets and preserve immutability; when working with hashable set objects as dictionary keys or set elements.

Contextos

Python code using frozenset for immutable set representations, e.g., in caching, graph algorithms, or when frozenset is required as a dict key.

Padrão

frozenset(iterable1) | frozenset(iterable2)

Estrutura central

frozenset(...) | frozenset(...)

Slots de substituição

iterable1: any iterable of hashable items, iterable2: any iterable of hashable items

Colocados típicos

  • frozenset constructor
  • set union operator |
  • frozenset.intersection
  • frozenset.difference

Substituições comuns

  • frozenset(set1).union(set2) or frozenset(set1 | set2) using mutable set union then converting.

Erros comuns

Using | on regular sets returns a mutable set, not frozenset; forgetting that frozenset is immutable and cannot be changed in-place.

Similar / contraste

frozenset(&) for intersection, frozenset(-) for difference, frozenset(^) for symmetric difference; using mutable set union set1 | set2.

Interferências

Coming from languages where '+' is used for set union (e.g., some Lisps), may mistakenly use + with frozenset, which raises TypeError.

Família do chunk

  • frozenset set operations

Nuance

The result is a new frozenset; original operands remain unchanged. Operator | works only with frozenset or set operands; mixing with non-set types raises TypeError.

Efeito pragmático

Provides an immutable, hashable set suitable for use as a dictionary key or set element.

Dica de memória

Think of the pipe as 'union' for frozensets, like set union but immutable.

Nota

The result is a new immutable frozenset; original operands remain unchanged. Using | with regular sets yields a mutable set.

Upgrade path

Consider using frozenset.union() for explicit intent, or convert to mutable set, union, then refreeze if mutability is needed.

Frequência: MediumFormulaicidade: Semi-fixedTipo de construção: binary operator expression using bitwise OR on frozenset operandsPrioridade de aquisição: Active recallPrioridade de output: BothTag de espaçamento: Immediate

Log in to save chunks.