কম্পিউটার

n অ্যারেতে সাধারণ উপাদান খুঁজে পেতে পাইথনে intersection_update()


এই নিবন্ধে, আমরা n অ্যারেতে সাধারণ উপাদানগুলি খুঁজে পেতে পাইথনে iintersection_update() সম্পর্কে শিখব।

সমস্যা হল যে আমাদেরকে তালিকা সম্বলিত একটি অ্যারে দেওয়া হয়েছে, প্রদত্ত অ্যারেগুলিতে সমস্ত সাধারণ উপাদানগুলি সন্ধান করুন?

অ্যালগরিদম

1.Initializingres with the first list inside the array
2.Iterating through the array containing lists
3.Updating the res list by applying intersection_update() function to check the common elements.
4.Finally returning the list and display the output by the help of the print statement.

এখন এর বাস্তবায়ন দেখে নেওয়া যাক

উদাহরণ

def commonEle(arr):

# initialize res with set(arr[0])
res = set(arr[0])

# new value will get updated each time function is executed
for curr in arr[1:]: # slicing
   res.intersection_update(curr)
return list(res)

# Driver code
if __name__ == "__main__":
   nest_list=[['t','u','o','r','i','a','l'], ['p','o','i','n','t'], ['t','u','o','r','i','a','l'],       ['p','y','t','h','o','n']]
   out = commonEle(nest_list)
if len(out) > 0:
   print (out)
else:
   print ('No Common Elements')


আউটপুট

['o', 't']

উপসংহার

এই নিবন্ধে, আমরা পাইথনে iintersection_update() সম্পর্কে শিখেছি যাতে n অ্যারেতে সাধারণ উপাদান খুঁজে পাওয়া যায় এবং এর বাস্তবায়ন।


  1. অ্যান্ড্রয়েড লিস্টভিউতে অ্যারে থেকে সাধারণ উপাদানগুলি কীভাবে খুঁজে পাবেন?

  2. সেলেনিয়াম এবং পাইথন উপাদান এবং পাঠ্য খুঁজে পেতে?

  3. পাইথনের একটি বাইনারি গাছে দুটি উপাদানের মধ্যে সাধারণ একটি পূর্বপুরুষ খুঁজে বের করার প্রোগ্রাম

  4. পাইথন প্রোগ্রাম তিনটি সাজানো অ্যারে সাধারণ উপাদান খুঁজে পেতে?