- Related Questions & Answers
- Find the Number Occurring Odd Number of Times using Lambda expression and reduce function in Python
- Java Program to Find the Number Occurring Odd Number of Times
- C/C++ Program to Find the Number Occurring Odd Number of Times?
- Python Program to Find Element Occurring Odd Number of Times in a List
- C/C++ Program for Finding the Number Occurring Odd Number of Times?
- Program to find most occurring number after k increments in python
- Python Program for Find sum of odd factors of a number
- The intersection of two arrays in Python (Lambda expression and filter function )
- Take an array and find the one element that appears an odd number of times in JavaScript
- Python Program to Search the Number of Times a Particular Number Occurs in a List
- Map function and Lambda expression in Python to replace characters
- Golang Program to find the odd-occurring elements in a given array
- Finding number that appears for odd times - JavaScript
- Python program to find the most occurring character and its count
- The most occurring number in a string using Regex in python

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Here given a user input positive integer array. Our task is to find out the number occurring odd number of times.

Input : A=[2, 4, 7, 7, 4, 2, 2] Output : 2

Step 1: Input Array element. Step 2: Write lambda expression and apply. Step 3: Reduce function over the input list until a single value is left. Step 4: Expression reduces the value of a^b into a single value. Step 5: a starts from 0 and b starts from 1.

# Python program to find the Number # Occurring Odd Number of Times # using Lambda expression and reduce function from functools import reduce def timeoccurrance(inp): print ("RESULT ::>",reduce(lambda a, b: a ^ b, inp))) # Driver program if __name__ == "__main__": A=list() n1=int(input("Enter the size of the List ::")) print("Enter the Element of List ::") for i in range(int(n1)): k=int(input("")) A.append(k) timeoccurrance(A)

Enter the size of the List :: 7 Enter the Element of List :: 1 2 3 2 3 1 3 RESULT ::> 3

Advertisements