इस लेख में हमें उस संख्या को ढूंढना है जो दी गई सूची में विषम बार आती है। हमें Lambda फ़ंक्शन और reduce फ़ंक्शन का उपयोग करने की भी आवश्यकता है।
हम एक फ़ंक्शन डिज़ाइन करते हैं जहां reduce फ़ंक्शन का उपयोग Lambda फ़ंक्शन को लागू करके किया जाता है ताकि जांचा जा सके कि तत्व विषम संख्या में मौजूद है।
उदाहरण
from functools import reduce
def oddcount(i):
print(reduce(lambda x, y: x ^ y, i))
listA = [12,34,12,12,34]
print("Given list:\n",listA)
print("The element present odd number of times:")
oddcount(listA)
आउटपुट
Given list: [12, 34, 12, 12, 34] The element present odd number of times: 12