Python သတ်မှတ်သည့် cross_update() နည်းလမ်း
ဥပမာ
x
နှင့် နှစ်ခုလုံးတွင် မရှိသောအရာများကို ဖယ်ရှားပါ y
။
x =
{"apple", "banana", "cherry"}
y = {"google",
"microsoft", "apple"}
x.intersection_update(y)
print(x)
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
နည်းလမ်း သည် intersection_update()
နှစ်စုံစလုံးတွင် မပါဝင်သောအရာများကို ဖယ်ရှားသည် (သို့မဟုတ် နှိုင်းယှဉ်မှုနှစ်ခုထက်ပိုပါက အစုံလိုက်အားလုံးတွင်)။
method သည် intersection_update()
method မှ ကွဲပြားသည် intersection()
၊ အကြောင်းမှာ
intersection()
method သည် မလိုအပ်သော အရာများမပါဘဲ
set အသစ်တစ်ခုကို ပြန်ပို့ပေးပြီးintersection_update()
method သည် မူရင်း set မှ မလိုလားအပ်သော အရာများကို ဖယ်ရှားပေး သောကြောင့် ဖြစ်သည်။
အထားအသို
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 sets ကို နှိုင်းယှဉ်ပြီး 3 set စလုံးတွင် ပါရှိသည့် အရာများနှင့်အတူ တစ်တွဲကို ပြန်ပေးသည်-
x =
{"a", "b", "c"}
y = {"c",
"d", "e"}
z = {"f",
"g", "c"}
x.intersection_update(y, z)
print(x)