Set Methods
intersection_update()
Update the set in place, keeping only elements common to it and all others.
set.intersection_update(*others)
set.intersection_update() modifies the set in place, retaining only elements that are also present in all others iterables.
Arguments
Parameters
| Name | Description |
|---|---|
| *others | One or more iterables to intersect with. |
Result
Returns
None, modifies the set in place.
Run it
Try it
Run it and change it
skills = {"Python", "SQL", "HTML", "CSS"}
required = {"Python", "SQL", "Docker"}
skills.intersection_update(required)
print(sorted(skills)) Output
Press Run to see what it prints.Worth knowing
- In-place operator: The
&=operator performs intersection update between sets.