Python Collection difference_update() Method
Example
Remove items that exist in both sets:
x = {"apple", "banana", "cherry"} y = {"google", "microsoft", "apple"} x.difference_update(y) print(x)
Definition and Usage
The different_update() method will remove items that exist in both sets.
The difference_update() method is different from the difference() method because the difference() method returns a new set without unnecessary items, while the difference_update() method removes unnecessary items from the original set.
Syntax
set.difference_update(set)
Parameter Values
Parameters | Description |
---|---|
set | Required. To check the differences in the collection. |