Q:

Find the number occurring odd number of times using lambda expression and reduce() function in Python

0

Example:

Input: 
list1 = [10, 20, 10, 30, 30, 20, 20]

Output:
20

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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)

Output:

20

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now