set

# Author:zhang 
# -*- coding:utf-8 -*-
'''set set is an unordered, non-repetitive data combination. Its main functions are as follows:
• Deduplication, turning a list into a set, It is automatically deduplicated.
• Relationship test, test the intersection, difference, union and other relationships between two sets
of data. Only
''' can be added to the
set list1 = set([1, 23, 456, 78, 5, ])
list2 = set([1, 56423, 23, 58, 456])
list3 = set([1, 23])
print(list1, "ddd", list2)
# Intersection: both have de
# and
print(list1. intersection(list2))
# Union: Unique # in both sets
or
print(list1.union(list2))
# Difference
print(list1.difference(list2))
print(list2.difference(list1))
print( list1 - list2)
# Parent set
print(list3.issubset(list1))
# Symmetric difference set removes the duplicates in the two sets
print(list1.symmetric_difference(list2))
print(list1 ^ list2)
# Intersection
print(list1 & list2)
# Union
print(list1 | list2)
list1.add(234)
print(list1)
len(list1) #Check the length of the set
list1.pop() #Delete any An element
list1.remove(23) #Delete an element
list1.discard(9999) #Delete the element, if the element does not exist, no error will be reported

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325123160&siteId=291194637
set
set