Alterna · учебный материал

Multiple

40.1: Multiples: Short theory, one example, and a step-by-step path Python.

Что в этом материале

Содержание и основные понятия

Many store only unique hash values and quickly check ownership.
substance and practice
Grade 11
EEG No. 24
01
How it works.
Many answer the question of ownership and store only unique hash elements. The order of the elements is not part of the set contract.
Unique.
The repeat add of the existing value does not change the size.
Supplies.
x in seen usually works quickly and is suitable for looking for repeats.
Algebra.
Unity, intersection, and difference create new multitudes.
All right.
For a stable conclusion, a lot of things have to be transferred to a sort.
02
One example in execution
Start the short program and go over the lines. The visualiser only shows the code, current line, variables and output.
An empty crowd creates
set()
:: Recording
{}
It creates a dictionary.
discard
removes the missing component safely, a
remove
Throws away
KeyError
.
pop
removes the arbitrary element, so it cannot be used for a predictable conclusion.
Algorithm map
Read from left to right, then run the code.
1
Start
2
Create Multiples
3
Add Value
4
Do you have another one?
5
Check and output
03
Remember
The list and dictionary cannot be placed in set: they are altered and not hashed.
Don't compare the string presentation set as an examination answer.
For the missing item, choose a discard or a clear test x in s.
Syntax of this page
set(iterable)
Creates many unique hash values.
add(x)
Adds x; duplicate is ignored.
discard(x)
Removes x without error if x is missing.
remove(x)
Removes x; the missing value causes KeyError.
pop()
Removes and returns the arbitrary element; the empty set calls KeyError.
update(iterable)
Adds all elements to iterable.
a | b / union
Combination of multiples.
a & b / intersection
Cross-section.
a - b / difference
Elements a missing in b.
sorted(set)
Creates an orderly list for a determinated output.
len
Considers unique elements.

Structural map of textbooks