Python | Find the Number Occurring Odd Number of Times using Lambda expression and reduce function Last Updated : 26 Feb, 2023 Summarize Comments Improve Suggest changes Share 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 Python | Find the Number Occurring Odd Number of Times using Lambda expression and reduce function 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 Sort Even-Placed in Increasing and Odd-placed Elements in Decreasing Order - Python We need to sort the elements at even indices in increasing order and the elements at odd indices in decreasing order. For example, given a list [10, 3, 5, 8, 2, 7, 6, 1], the result should be [2, 8, 5, 7, 6, 3, 10, 1]. Let us explore different ways to achieve this in Python.Using List Comprehension 3 min read Like