Python 3 reference · Set Methods
Python Set difference_update() Method
Remove from this set every element found in the others, in place. The same as a -= b.
Python 3 Since 3.0
Syntax
set.difference_update(*others)
Parameters
| Parameter | Description |
|---|---|
*others |
One or more iterables. |
Return value
None.
Examples
todo = {"a", "b", "c"}
todo.difference_update(["b"])
print(sorted(todo))
Output
['a', 'c']
s = {1, 2, 3}
s -= {1}
print(s)
Output
{2, 3}Version history
| Version | Change |
|---|---|
| Python 3.0 | Added |
Related
set.difference()· Return a new set with the elements of this set that are not in the others. The same as a - b.set.discard()· Remove an element if it is present; do nothing if it isn't. The no-error version of remove().- Python Sets · tutorial