Python | Find the Number Occurring Odd Number of Times using Lambda expression and reduce function Last Updated : 26 Feb, 2023 Comments Improve Suggest changes Like Article Like Report Given an array of positive integers. All numbers occur even number of times except one number which occurs odd number of times. Find the number in O(n) time & constant space. Examples: Input : [1, 2, 3, 2, 3, 1, 3] Output : 3 We have existing solution for this problem please refer Find the Number Occurring Odd Number of Times link. we will solve this problem in python quickly using Reduce(expression, iterable) method. Python3 # Python program to Find the Number # Occurring Odd Number of Times # using Lambda expression and reduce function from functools import reduce def oddTimes(input): # write lambda expression and apply # reduce function over input list # until single value is left # expression reduces value of a ^ b into single value # a starts from 0 and b from 1 # ((((((1 ^ 2)^3)^2)^3)^1)^3) print (reduce(lambda a, b: a ^ b, input)) # Driver program if __name__ == "__main__": input = [1, 2, 3, 2, 3, 1, 3] oddTimes(input) Output: 3 Time complexity: O(n)Auxiliary space: O(1) Comment More infoAdvertise with us Next Article Number of ways to choose a pair containing an even and an odd number from 1 to N S Shashank Mishra Follow Improve Article Tags : Python python-string python-lambda Practice Tags : python Similar Reads Python Program to Find the Number Occurring Odd Number of Times Write a Python program for a given array of positive integers. All numbers occur an even number of times except one number which occurs an odd number of times. Find the number in O(n) time & constant space. Examples : Input: arr = {1, 2, 3, 2, 3, 1, 3}Output : 3 Input: arr = {5, 7, 2, 7, 5, 2, 5 3 min read Number of ways to choose a pair containing an even and an odd number from 1 to N Given a number N the task is to find the number of pairs containing an even and an odd number from numbers between 1 and N inclusive. Note: The order of numbers in the pair does not matter. That is (1, 2) and (2, 1) are the same. Examples: Input: N = 3 Output: 2 The pairs are (1, 2) and (2, 3).Input 3 min read Sum Even and Odd Values with One For-Loop and No If-Condition Using Python Summing even and odd numbers in a list is a common programming task. Typically, we'd use an if condition to check whether a number is even or odd. However, we can achieve this in Python efficiently using arithmetic operators and list slicing, without relying on if conditions. In this article, we'll 4 min read Print powers using Anonymous Function in Python Prerequisite : Anonymous function In the program below, we have used anonymous (lambda) function inside the map() built-in function to find the powers of 2. In Python, anonymous function is defined without a name. While normal functions are defined using the def keyword, in Python anonymous function 2 min read Python Program to Count Even and Odd Numbers in a List In Python working with lists is a common task and one of the frequent operations is counting how many even and odd numbers are present in a given list. The collections.Counter method is the most efficient for large datasets, followed by the filter() and lambda approach for clean and compact code. Us 4 min read Python Program to Count Even and Odd Numbers in a List In Python working with lists is a common task and one of the frequent operations is counting how many even and odd numbers are present in a given list. The collections.Counter method is the most efficient for large datasets, followed by the filter() and lambda approach for clean and compact code. Us 4 min read Like