Definition
The intersection_update() method removes the items that is not present in both sets (or in all sets if the comparison is done between more than two sets).
Syntax
set.intersection_update(set1, set2 ...)
Parameters
Parameter | Description |
---|---|
set1 | Required. The set to search for equal items in |
set2... | Optional. The other set to search for equal items in. You can compare as many sets you like. Separate the sets with a comma |
Examples:
persons1 = {"Mark", "Jeff", "Ivan", "Mike"}
persons2 = {"Arnel", "Marie", "Ivan", "Alex"}
persons1.intersection_update(persons2)
print(persons1)
# example with 3 sets
persons1 = {"Mark", "Jeff", "Ivan", "Mike"}
persons2 = {"Arnel", "Marie", "Ivan", "Alex"}
persons3 = {"Ivan", "Cindy", "Sarah", "Igor"}
persons1.intersection_update(persons2, persons3)
print(persons1)