Set set (set is an unordered and non-repeating collection of elements)

Source: Internet
Author: User
Tags set set

Function:

One, you can remove the list, duplicate items in the tuple

Second, can be used for intersection, collection, difference set, etc.

def add (self, *args, **kwargs):

      "" Add " " "

  S1 = (1,2,3 , 4,2,3,1) 
S3 = set ( s1)
S4 = S3.add (5)
print ( s1)
print (S3)
print (S4)
(1, 2, 3, 4 , 2, 3, 1)
{1, 2, 3, 4, 5}
None

def clear (Self, *args, **kwargs):
"Clear all elements"
S1 = (1,2,3,4,2,3,1)
Set (s1)
S4 = S3.clear ()
Print (s1)
Print (S3)
Print (S4)
(1, 2, 3, 4, 2, 3, 1)
Set ()
Non

def copy (self, *args, **kwargs):
"Copy a Set"
S1 = (1,2,3,4,2,3,1)
Set (s1)
S4 = S3.copy ()
Print (s1)
Print (S3)
Print (S4)
(1, 2, 3, 4, 2, 3, 1)
{1, 2, 3, 4}
{1, 2, 3, 4}

def difference (self, *args, **kwargs):
"' A.difference (b) A and B differential set, showing the result of a" '
  S1 = (1,2,3 , 4,2,3,1) 
S2 = (3,4,5,< Span style= "color: #0000ff;" >7,1)
S5 = set (s2)
S3 = set ( s1)
S4 = s3.difference (s2)
print (S3)
print (S5)
print (S4)
{1, 2, 3, 4}
{1, 3, 4, 5, 7}
{2}

 def difference_update (self, *args, **kwargs):  
" Delete all elements contained in B in the current A, and delete the ' '
directly in the original collection
  S1 = (1,2,3 , 4,2,3,1) 
S2 = (3,4,5,< Span style= "color: #0000ff;" >7,1)
S5 = set (s2)
S3 = set ( S1)
print (s3)
S4 = S3.difference_ Update (s2)
print (S3)
print (S5)
print (S4)
{1, 2, 3, 4}
{2}
{1, 3, 4, 5, 7}
None

 def discard (self, *args, **kwargs):  
' ' removes elements from the collection and removes ' '
directly from the original collection
  S1 = (1,2,3 , 4,2,3,1) 
S2 = (3,4,5,< Span style= "color: #0000ff;" >7,1)
S5 = set (s2)
S3 = set ( S1)
print (s3)
S4 = S3.discard (2)
print (S3)
print (S5)
print (S4)
{1, 2, 3, 4}
{1, 3, 4}
{1, 3, 4, 5, 7}
None
 def intersection (self, *args, **kwargs):  
" "" take intersection, create a new set ""
  S1 = (1,2,3 , 4,2,3,1) 
S2 = (3,4,5,< Span style= "color: #0000ff;" >7,1)
S5 = set (s2)
S3 = set ( S1)
print (S3)
print (s5)
S4 = s3.intersection (S5)
print (S3)
print (S4)
{1, 2, 3, 4}
{1, 3, 4, 5, 7}
{1, 2, 3, 4}
{1 , 3, 4}


 def intersection_update (self, *args, **kwargs):  
" Take the intersection and modify the original set '
  S1 = (1,2,3 , 4,2,3,1) 
S2 = (3,4,5,< Span style= "color: #0000ff;" >7,1)
S5 = set (s2)
S3 = set ( S1)
print (S3)
print (s5)
S4 = S3.intersection_update (S5)
Print (S3)
print (S4)
{1, 2, 3, 4}
{1, 3, 4, 5, 7}
{1, 3, 4}
None


 def isdisjoint (self, *args, **kwargs):  
" '
 S1 = (1,2,3,4,2,3,1) 
S2 = ( Span style= "color: #0000ff;" >3,4,5,7,1)
S5 = set (s2)
S3 = set (S1)
print (S3)
print (s5)
S4 = S3.isdisjoint (S5)
print (S3)
print (S4)
{1, 2, 3, 4}
{1, 3, 4, 5, 7}
{1, 2, 3, 4}
False

def issubset (self, *args, **kwargs):
"' is a subset '

""""""  
def pop (self, *args, **kwargs):
' remove '


""""""   
        "" " difference set, create new Object "  ""
def symmetric_difference_update (self, *args, **kwargs):
""""""   
       """"""
  """"""

      

  

  

  

    

      

      

      

Set set (set is an unordered and non-repeating collection of elements)

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.