Python-set collection

set collection: nature is an unordered collection, but only stores a dictionary key, is not stored in the dictionary value.
set with elements of the collection dictionary key elements have a common feature:
1.set elements in a set is only
2.set elements in the set is immutable

Create set collections:
setl = set () # Create an empty set set
set2 = {1,2,3} # Create a set of elements having a set of
set3 = set ([]) # Create a collection set

set1.add (ele)
function: add to set1 elements,
pay attention: when set1 collection elements and added the elements of duplication, will not have any effect, but it is not an error.
Added elements must be immutable type, variable type of element is being given.

set1.update (sequence)
Function: The sequence inserted into the broken element in set1
Note: when using the update function, which must be a sequence parameter.

set1.remove (ele)
function: the specified element removal

set collection of traversal
for in the X-SET1:
    Pass

set1 & set2 obtain two sets of intersection of the sets [] elements overlap
set1 | set2 obtain and set the set of all elements of the two sets of [removing overlapping portions]

set collection of the most commonly used functions is to go heavy.

Guess you like

Origin blog.csdn.net/lonely2018/article/details/91609331