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.
Parameters
| Name | Description |
|---|---|
| *others | One or more iterables to intersect with. |
Returns
None — modifies the set in place.
Try it
Run it and change it
skills = {"Python", "SQL", "HTML", "CSS"}
required = {"Python", "SQL", "Docker"}
skills.intersection_update(required)
print(sorted(skills))Worth knowing
- In-place operator: The
&=operator performs intersection update between sets.