阿毛Alex - 2025年6月16日
type: channel
link: https://alexmao.com/index.php/2025/06/16/
description: 生命不息，折腾不止
items: Python的sets操作
items: Dictionary的方法

Python的sets操作
type: item
date: 2025-06-16T09:43:09+00:00
description: x.union(y) This method returns all the unique items that are present in the two sets, as a new set. x_set | y_set x.intersection(y) This method returns the common items that are present in two sets, as a new set. x_set & y_set difference_update () This method removes all the elements of 'set 2' common to 'set 1' in 'set1'. It updates 'set 1'. x.isdisjoint(y) This method returns True if two sets have null intersection. y.issubset(x) This method returns True for 'Set 2', if all the elements of 'Set 2' are present in 'Set 1' x.issuperset(y) This method returns True for 'Set 1' if all the elements of Set 2 are present in 'Set 1'. x.add(e) It adds a single item to the set and updates the set. x.discard(e) It removes a single item from the set and updates it. x.pop () It pops and returns any arbitrary item from the set. x.copy () It creates a shallow copy of any set. x.clear() It clears all the items of the set.

Dictionary的方法
type: item
date: 2025-06-16T09:24:05+00:00
description: len (x_dict)To know the number of key: value pairs in the dictionary.x_dict.keys ( )Returns all the 'keys' of dictionariesx_dict.values ( )Returns all the 'values' of dictionariesThe del statementIt is used for deleting any keys from the dictionary.x_dict.pop (key)It will pop a 'value' of the required key.sorted (x_dict)The dictionary will get sorted by its values.x_dict.clear ()Clears all the content of the dictionary