Article From:https://www.cnblogs.com/fxc-520520/p/9123523.html
# pythoners=['Wang cannon, 'Li Er Ya', 'Chen Duxiu', 'Alex','wxx',' Oude fraternity ']
# linuxers=['Chen Duxiu ','wxx','egon',' whole egg ']
#
# l1=[]
# for stu in pythoners:
# if stu in linuxers:
# # print(stu)
# l1.append(stu)
#
# print(l1)
#
# l2=[]
# for stu in pythoners:
# if stu not in linuxers:
# # print(stu)
# l2.append(stu)
#
# print(l2)



#First: basic use
# 1 Use: relation operation and weight removal
#
# 2 Definition: {} separates multiple elements with commas, each element must be immutable (hash) type.
#Emphasize:
#2.1 The elements in the collection must be immutable (hash) type.
#2.2 Element disorder within a set
#2.3 The elements in the set cannot be repeated

# s={1,2,'a'} #s=set({1,2,'a'}) #Set type.
# print(type(s))

# s={1.1,1,'aa',(1,2,3),{'a':1}} #There will be a mistake, because the dictionary is a variable type.

# s={1,'a','hello',(1,2,3),4}
# for item in s:
# print(item) #Unordered values are taken out

# s={1,1,1,1,1,1,1,1,1,'a','b','a'}
# s={(1,2,3),(1,2,3),'a','b','a'}
# print(s) #Repeating

# s=set('hello')
# print(s) #Out of order, and go back to weight

# The only thing we need to pay attention to is simply using the set.
#1、The value of a deweighted target must be immutable.
#2、The result of weight removal will disrupt the original order
# names=['asb','asb','asb','wsb','wsb','egon_nb',[1,2,3]]
# s=set(names)

# names=list(s)
# print(names)

#
# 3 Common operation + built-in method
#First - mastered operations:
#1、Length len
# pythoners={'Wang cannon, 'Li Er Ya', 'Chen Duxiu', 'Alex','wxx',' Oude fraternity '
# print(len(pythoners)) #The number of elements

#2、Member operations in and not in
# print('Li Er 's' in pythoners'


pythoners={'Wang cannon, 'Li Er Ya', 'Chen Duxiu', 'Alex','wxx',' Oude fraternity '
linuxers={'Chen Duxiu ','wxx','egon',' Zhang Quan 'egg']
#3、|Union
# print(pythoners | linuxers) #All the people, the repeating people only write one
# print(pythoners.union(linuxers)) #All the people, the repeating people only write one

#4、&intersection
# print(pythoners & linuxers) # Take a repeat of the intersection
# print(pythoners.intersection(linuxers))
# print(linuxers & pythoners)
#5、-Difference set
# print(pythoners - linuxers)
# print(pythoners.difference(linuxers))
# print(linuxers - pythoners)
# print(linuxers.difference(pythoners))
#6、^Symmetric difference set
# print(pythoners ^ linuxers)
# print(pythoners.symmetric_difference(linuxers))

# print(linuxers ^ pythoners)
#7、==
# s1={1,2,3}
# s2={1,2,3}
# print(s1 == s2)

#8、The parent set (including the relationship):> > =
# s1={1,2,3,4,5}
# s2={1,2,3}
# print(s1 > s2) # s1Include S2
# print(s1.issuperset(s2))
# print(s2.issubset(s1))

# s3={1,2,10}
# print(s1 > s3)

# s1={1,2,3,4,5}
# s2={1,2,3,4,5}
# print(s1 >= s2)

#9、Subsets (included relations):< < =

s1={1,2,3,4,5}
# s1.add(6)
# print(s1)

# s1.update({4,7,8,9})
# print(s1)

# res=s1.pop()
# print(res)

# res=s1.remove(4)
# print(res)
# print(s1)

s1={1,2,3,4,5}
s2={2,3,7,8}
# s1=s1 - s2
# print(s1)
# s1.difference_update(s2) # s1=s1 - s2
# print(s1)

# s1={1,2,3,4,5}
# s1.pop()
# s1.remove(7)
# s1.discard(7) # Even if the element to be deleted does not exist, it will not make a mistake.

# s1={1,2,3,4,5}
# s2={5,6,7,8}
# print(s1.isdisjoint(s2))



#
# #Two: a summary of this type
# 1 Save a value of or to save multiple values
# Multiple values can be stored, and values must be immutable.
#
# 2 Ordered or disorder
# disorder
#
# 3 Variable or immutability
# setA set is a variable type
# s={1,2,3}
# print(id(s))
# s.add(4)
# print(s)
# print(id(s))



#=====================The weight of the set = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
# The only thing we need to pay attention to is simply using the set.
#1、The value of a deweighted target must be immutable.
#2、The result of weight removal will disrupt the original order
# names=['asb','asb','asb','wsb','wsb','egon_nb',[1,2,3]]
# s=set(names)

# names=list(s)
# print(names)

stu_info=[
{'name':'egon','age':18,'sex':'male'},
{'name':'egon','age':18,'sex':'male'},
{'name':'egon','age':18,'sex':'male'},
{'name':'alex','age':73,'sex':'male'},
{'name':'oldboy','age':84,'sex':'female'},
]

new_info=[]
for info in stu_info:
if info not in new_info:
new_info.append(info)

print(new_info)


Similar Posts:

Link of this Article: Set type

Leave a Reply

Your email address will not be published. Required fields are marked *