collection of basic data types
Set
Set set, which is an unordered and non-repeating collection of elements
1 #set does not allow duplicate collection set allow duplicate list but the collection is unordered2 #For example3 #s = {1,23,23,4,55,55}4 #print (s) # result {1, 4, at5 6 #1. Create7 #s = set ()8 #s = {11,22,33,44}9 Ten #2. Conversion One #L = list () A #s = set () #创建集合 - #s = set ([11,22,33,11,22]) # turns the list into a set - the #3. Built-in method of collection - - #1 add Z adds elements within the collection, do not add only one element in the collection - #se = {1,2,3,3} + #Se.add (+) - #print (SE) + A #2 Clear Cleanup collection at #S1 = {11,22,33,44,55} - #s1.clear () - #print (S1) - - #3 Difference- number represents the difference set - #S1 = {11,22,33,44,55} in #s2 = {22,55,66} - #Ret1 = s1.difference (s2) #找s1中存在, a collection that does not exist in S2 #s1-s2 to #Ret2 = s2.difference (S1) #找s2中存在, a collection that does not exist in S1 #s2-s1 + #print (RET1) - #print (Ret2) the * #4 difference_update $ #S1 = {11,22,33,44,55}Panax Notoginseng #s2 = {22,55,66} - #ret = s1.difference_update (s2) the ## Find the S1 in the S2, the collection that doesn't exist, update yourself + #print (S1) A #print (ret) the + #5 Discard Remove specified element no error - #S1 = {11,22,33,44,55} $ #S1.discard (+) $ #S1.remove (one) #移除指定元素, no error - #print (S1) - the #6 intersection intersection & - #se = {11,22,33}Wuyi #Be = {22,95, "Suibian"} the ## ret = se.intersection (BE) - ## se.intersection_update () Wu ## Print (ret) - ## Print (SE) About #ret = se.isdisjoint(BE) #判断来个是否由交集 Yes false no true $ #print (ret) - - #7 issubset sub-sequence - #se = {11,22,33,44} A #Be = {11,22} + #ret = Se.issubset (BE) the # - #Ret1 = se.issuperset(BE) # parent sequence $ #print (ret) the #print (RET1) the the #8 #随机删除一个值 and return value the #se = {11,22,33,44} - #ret = se.pop() in #print (ret) the the #9 symmetric_difference ^ # Complementary Set #去除两个集合相同部分, leaving a different element About #se = {11,22,33,44} the #Be = {11,22,55,77} the #ret = se.symmetric_difference (BE) the #print (ret) + # - ## Union | # intersection # Find the public part of two sets the #ret = se.union (BE)Bayi #print (ret) the the #Update list - #se = {11,22,33,44} - #se.update ([44,55]) the #print (SE)
Python's path "fourth" a collection of basic data types for Python basics