python--Set Set type

Source: Internet
Author: User

Set Set type *****************

  1. 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 "/>

  2. 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 "/>

  3. 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

  4. 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

  5. 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!

  6. 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


python--Set Set type

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.