
- 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
Write a program in Python to check if a series contains duplicate elements or not
Input − Assume, you have the following series,
0 1 1 2 2 3 3 4 4 5
The above series contains no duplicate elements. Let’s verify using the following approaches.
Solution 1
Assume, you have a series with duplicate elements
0 1 1 2 2 3 3 4 4 5 5 3
Set if condition to check the length of the series is equal to the unique array series length or not. It is defined below,
if(len(data)==len(np.unique(data))): print("no duplicates") else: print("duplicates found")
Example
import pandas as pd import numpy as np data = pd.Series([1,2,3,4,5]) result = lambda x: "no duplicates" if(len(data)==len(np.unique(data))) else "duplicates found!" print(result(data))
Output
no duplicates
Solution 2
Example
import pandas as pd import numpy as np data = pd.Series([1,2,3,4,5,3]) if(len(data)==len(np.unique(data))): print("no duplicates") else: print("duplicates found")
Output
duplicates found!
- Related Articles
- Write a program in Python to remove the elements in a series, if it contains exactly two spaces
- Write a C# program to check if a number is Palindrome or not
- Write a C# program to check if a number is prime or not
- Write a program in Python to filter the elements in a series which contains a string start and endswith ‘a’
- Python program to check if a string is palindrome or not
- Python program to check if a number is Prime or not
- Program to check string contains consecutively descending string or not in Python
- Golang Program to check a string contains a specified substring or not
- Check if a Java ArrayList contains a given item or not
- Program to check some elements in matrix forms a cycle or not in python
- PHP program to check if a given number is present in an infinite series or not
- Python program to check if a given string is Keyword or not
- Check if a given array contains duplicate elements within k distance from each in C++
- Check if a binary string contains consecutive same or not in C++
- Write a Python program to shuffle all the elements in a given series

Advertisements