Python code to find the number occurring odd number of times using lambda expression and reduce() function
Define a lambda function and use reduce() function over the list until the single value is left expression reduces the value of x ^ y into single value x starts from 0 and y from 1.
# Importing redecue() function
from functools import reduce
def findElement(list1):
print (reduce(lambda x, y: x ^ y, list1))
# Main function
if __name__ == "__main__":
list1 = [10, 20, 10, 30, 30, 20, 20]
findElement(list1)
Python code to find the number occurring odd number of times using lambda expression and reduce() function
Define a lambda function and use reduce() function over the list until the single value is left expression reduces the value of x ^ y into single value x starts from 0 and y from 1.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer