Is the python collection a variable summary

Time:2019-9-28

A set is an unordered variable sequence. The elements in a collection must be hash-able, that is, immutable data types.

Empty set

a=set()

Note that a={} creates an empty dictionary.

Set — Variable sets. Elements in a collection can be added or deleted dynamically.

Frozenset — an immutable set. Elements in a collection are immutable.

Note: For union, intersection, difference set, etc., the return value has the same type as the leftmost operand. For example, S & T takes intersection. S set is a set type set, t set is a frozenset type set, then the result will be set type set.

You can also use set () to convert to collections


b=[1,2,3,4]

a=set(b)

a

{1,2,3,4}

You can also create a collection with {}


a={1,2,3,4,1}

a

{1,2,3,4}

Like dictionaries, because collections are disordered, only one of them is retained when there are repetitive elements.

An immutable set is an unordered immutable set.

Create with frozenset (seq)


a=frozenset([1,2,3,(1,2,4)])

a

frozenset({1,2,3,(1,2,4)})

Elements can only be hash


frozenset([1,2,3,[1,2,4]])

error

It is mainly used as the key of dictionary. The difference between tuple and tuple is disorder, elements are not repeatable, and elements can only be immutable types.

Description: Other combinatorial data types can be transformed into immutable set types (or variable set types can be transformed into immutable set types frozenset), returning an immutable set with no duplicate elements and arbitrary ordering.

Frozenset () function

Syntax: frozenset () – > empty frozenset object returns an invariant empty set

Frozenset (iterable) – > frozenset object returns an immutable new collection

Iterable — The combined data type to be transformed.