- 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

# Program to find which element occurs exactly once in Python

Suppose we have a list of numbers called nums where each value occurs exactly three times except one value that occurs once. We have to find the unique value. We have to solve it in constant space.

So, if the input is like nums = [3, 3, 3, 8, 4, 4, 4], then the output will be 8

To solve this, we will follow these steps −

m := a map with different values and their frequencies

return the value with minimum frequency

Let us see the following implementation to get better understanding −

## Example

from collections import Counter class Solution: def solve(self, nums): nums = Counter(nums) return min(nums, key=nums.get) ob = Solution() nums = [3, 3, 3, 8, 4, 4, 4] print(ob.solve(nums))

## Input

[3, 3, 3, 8, 4, 4, 4]

## Output

8

- Related Articles
- 8085 program to find the element that appears once
- Program to count k length substring that occurs more than once in the given string in Python
- Find an integer X which is divisor of all except exactly one element in an array in Python
- Program to find next board position after sliding the given direction once in Python
- Which event occurs in JavaScript when an element is dragged completely?
- Which event occurs in JavaScript when a dragged element is dropped?
- Which event occurs in JavaScript when an element is getting dragged?
- Program to find number of sublists that contains exactly k different words in Python
- Python Program to find largest element in an array
- Which event occurs in JavaScript when an element is content is copied to clipboard?
- Find the element that appears once in sorted array - JavaScript
- Which event occurs in JavaScript when the dragging of an element begins?
- Program to find smallest index for which array element is also same as index in Python
- Python Program to find the largest element in an array
- Python Program to find the largest element in a tuple

Advertisements