Q:

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

belongs to collection: Python Lambda Function Programs

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)

Check if value is in a List using Lambda Function ... >>
<< Find small number between two numbers using Lambda...