Python Setintersection_update ()メソッド
例
x
との両方に存在しないアイテムを削除しますy
。
x =
{"apple", "banana", "cherry"}
y = {"google",
"microsoft", "apple"}
x.intersection_update(y)
print(x)
定義と使用法
このintersection_update()
メソッドは、両方のセット(または、3つ以上のセット間で比較が行われる場合はすべてのセット)に存在しないアイテムを削除します。
このメソッドは、不要なアイテムを含まない
新しいセットを返し、元のセットから不要なアイテムを削除するため、
メソッドintersection_update()
とは異なります。intersection()
intersection()
intersection_update()
構文
set.intersection_update(set1, set2 ... etc)
パラメータ値
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 |
その他の例
例
3つのセットを比較し、3つのセットすべてに存在するアイテムを含むセットを返します。
x =
{"a", "b", "c"}
y = {"c",
"d", "e"}
z = {"f",
"g", "c"}
x.intersection_update(y, z)
print(x)