-
Definition of a collection
set = {}
Set = {A-i}
Set = {1,2,3,1,2,3}
set = {, ' Hello '}
Set = {A-st, ' Hello ', (+/-)}
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/9B/EE/wKioL1lo1S7D_QN-AAD8J-5mSyk404.png "title=" 234520170714222452.png "style=" Float:none; "alt=" Wkiol1lo1s7d_qn-aad8j-5msyk404.png "/>650" this.width=650; "src = "Https://s2.51cto.com/wyfs02/M00/9B/EF/wKiom1lo1S_xGetaAACYAleREg0537.png" title= "234520170714222507.png" style = "Float:none;" alt= "Wkiom1lo1s_xgetaaacyalereg0537.png"/>650) this.width=650; "Src=" https://s2.51cto.com/ Wyfs02/m00/9b/ef/wkiom1lo1s-idlt8aaeh3wf-czc787.png "title=" 234520170714222541.png "style=" Float:none; "alt=" Wkiom1lo1s-idlt8aaeh3wf-czc787.png "/>
The collection does not repeat:
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/9B/EF/wKiom1lo1S6AYOogAAEkJE8apFs592.png "style=" float : none; "title=" 234520170714222421.png "alt=" Wkiom1lo1s6ayoogaaekje8apfs592.png "/>
List converted to: 650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9B/EE/wKioL1lo1TCTxWkqAADckbMoU0Y705.png "title= "234520170714222556.png" style= "Float:none;" alt= "Wkiol1lo1tctxwkqaadckbmou0y705.png"/>
Example:
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9B/EE/wKioL1lo1TCSp4EsAACthgLX3gk257.png "title=" 234520170714222623.png "style=" Float:none; "alt=" Wkiol1lo1tcsp4esaacthglx3gk257.png "/>
-
Application Scenarios for Set
A collection is an unordered, non-repeating combination of data.
collection to remove duplicate elements from the list.
A collection has properties that are not available for other data types, that is, relationship tests, including the intersection, the difference set, the set, whether it is a subset, whether it is a parent set, and so on.
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/9B/EF/wKiom1lo1THChIr3AADlMthootM739.png "style=" float : none; "title=" 234520170714222710.png "alt=" Wkiom1lo1thchir3aadlmthootm739.png "/>
-
Relationship test actions for collections
Intersection: List_1.intersection (list_2)
Set: List_1.union (list_2)
Difference set: List_1.difference (list_2)
List_2.difference (list_1)
Equivalent differential list_1.symmetric_difference (list_2)
Subset List_1.issubset (list_2)
Parent set List_1.issuperset (list_2)
With or without intersection list_1.isdisjoint (list_2)
Intersection: List_1 & list_2
Set: List_1 | List_2
Difference set: list_1-list_2
List_2-list_1
Peer differential
list_1 ^ list_2
-
Collection of additions
S.add (1)
Add an item to the collection
S.update ([1,3,4])
Add multiple items to the collection, followed by a parameter that should be an iterative type
-
Collection of deletions
S.remove (1)
Deletes the specified element from the collection
S.pop ()
Randomly deletes an element in the collection and returns the deleted element
S.clear ()
Empties all elements of the collection over!
-
Other operations of the collection
Len (s)
Show the length of set set
"1" in S
Detects whether an element is a member of the collection S and returns additional operations for the Boolean collection
S.copy ()
The shallow copy of the collection, not in-depth study here, will be said later