Python သတ်မှတ် လမ်းဆုံ() နည်းလမ်း
ဥပမာ
set နှစ်ခုလုံးတွင် ပါရှိသည့်အရာများပါရှိသော set တစ်ခုကို ပြန်ပေးပါ
x
၊ နှင့် set y
:
x =
{"apple", "banana", "cherry"}
y = {"google",
"microsoft", "apple"}
z = x.intersection(y)
print(z)
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
နည်းလမ်း သည် intersection()
နှစ်ခု သို့မဟုတ် ထို့ထက်ပိုသောအတွဲများကြားတွင် ဆင်တူယိုးမှားပါရှိသော အစုံကို ပြန်ပေးသည်။
အဓိပ္ပါယ်- ပြန်ပေးသည့်အစုံတွင် နှစ်စုံထက်ပို၍ နှိုင်းယှဉ်ပါက အတွဲနှစ်ခုစလုံးတွင် ရှိသောအရာများသာ ပါ၀င်သည်။
အထားအသို
set.intersection(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"}
result = x.intersection(y, z)
print(result)