
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Find the Number Occurring Odd Number of Times using Lambda expression and reduce function in Python
In this article we are required to find that number from the list which occurs odd number of times in the given list. We are also required to use the Lambda function and the reduce function.
We design a function where the reduce function is used by applying the Lambda function to check if the element is present odd number of times.
Example
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)
Output
Running the above code gives us the following result −
Given list: [12, 34, 12, 12, 34] The element present odd number of times: 12
- Related Articles
- 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?
- The intersection of two arrays in Python (Lambda expression and filter function )
- The most occurring number in a string using Regex in python
- Map function and Lambda expression in Python to replace characters
- Program to find number of sub-arrays with odd sum using Python
- Find the Number of Subarrays with Odd Sum using C++
- Program to find most occurring number after k increments in python
- Golang Program to check the given number is an odd number using library function
- Haskell Program to check the given number is an Odd number using library function
- Take an array and find the one element that appears an odd number of times in JavaScript
- Find sum of odd factors of a number using C++.
- Find the Number of Subarrays with m Odd Numbers using C++

Advertisements