Python 3 reference · Set Methods
Python Set intersection_update() Method
Keep only the elements found in this set and all others, in place. The same as a &= b.
Python 3 Since 3.0
Syntax
set.intersection_update(*others)
Parameters
| Parameter | Description |
|---|---|
*others |
One or more iterables. |
Return value
None.
Examples
allowed = {"read", "write", "admin"}
allowed.intersection_update({"read", "write"})
print(sorted(allowed))
Output
['read', 'write']
s = {1, 2, 3}
s &= {2, 3, 4}
print(s)
Output
{2, 3}Version history
| Version | Change |
|---|---|
| Python 3.0 | Added |
Related
set.intersection()· Return a new set with the elements common to this set and all others. The same as a & b.- Python Sets · tutorial