Python Set intersection_update() Method
Removes the items in the sets involved in the operation so that only items present in all sets will remain in each set.
This is in contrast to intersection
which
simply returns a new set rather than modifying the sets involved.
Syntax
Python
Copy Code
set.intersection_update(set1 [, set2, ...])
Parameters
Parameter | Description |
---|---|
set1 [, set2, ...] |
Required. One or more sets that will be modified based on the intersection of the sets' items. |
Example
Python
Copy Code
desktopComponents = {'memory', 'processor', 'hard drive'} laptopComponents = {'memory', 'processor', 'SSD', 'camera', 'keyboard'} laptopComponents.intersection_update(desktopComponents) print(laptopComponents)
Output
{'memory', 'processor'}