python container -set / tuple


#tuple
created:
tuple name = (20) # special attention when a plus,
tuple name = (1, 2, 3)
tuple name = 100,200,300
yuan Group name = tuple (iterable)

Value:
variable name = tuple [index]
for in Item tuple name:
xxx


No tuple derived formula:

t = (i for i in range (10)) # Builder

 

 

Create a fixed set #set: frozenset (iterables) immutable
created:
collection name = set () # a = { } empty dictionary
collectionname = {1, 2, 3}
collection name = SET (iterables)

Additions:
a collection of name .add (elements) # set of natural de-duplication, the original collection did not increase, there is no change in
the collection name .discard (element)


Operation:
operation
1 & intersection: return to common elements.
. 1 = {S1, 2,. 3}
S2 = {2,. 3,. 4}
S3 = {S1 & S2 # 2,. 3}

2. Set and: Returns repeating elements
S1 = {. 1, 2,. 3}
S2 = {2,. 3,. 4}
S3 = S1 | S2 # {. 1, 2,. 3,. 4}

3. Set up: - return only one of the elements belonging to
s1 = {. 1, 2,. 3}
s2 = {2,. 3,. 4}
s1 - s2 # {}. 1, but not belonging s2 s1

Complement ^: return different elements
S1 = {. 1, 2,. 3}
S2 = {2,. 3,. 4}
S3 = S1 ^ S2. 1 {#,}. 4 is equivalent to (s1-s2 | s2-s1 )

4. subset <: determining whether all elements of a complete set of another set
5. superset>: determining whether a set of all the elements of another set
S1 = {. 1, 2,. 3}
S2 = {2, }. 3
S2 <S1 # True
S1> S2 # True

6 = the same or different ==:! Whether all elements in the set and another set of the same.
. 1 = {S1, 2,. 3}
S2 = {. 3, 2,. 1}
S1 S2 # == True
S1! = S2 # False
subset or the same, or the same superset <=> =

 


Common method
update () to set the additive element iterables
clear () Removes all elements in the set
copy () copies a set
pop () to remove the random element

 

Guess you like

Origin www.cnblogs.com/chenlulu1122/p/11921763.html