
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to print the duplicate elements of an array
When it is required to print the duplicate elements of an array, the list elements are iterated over, and a nested loop is used.
Below is a demonstration of the same −
Example
my_list = [1, 2, 5, 6, 8, 9, 3, 4, 8, 9, 1, 8] print("The list is :") print(my_list) print("The duplicate elements in the list are : ") for i in range(0, len(my_list)): for j in range(i+1, len(my_list)): if(my_list[i] == my_list[j]): print(my_list[j])
Output
The list is : [1, 2, 5, 6, 8, 9, 3, 4, 8, 9, 1, 8] The duplicate elements in the list are : 1 8 8 9 8
Explanation
A list is defined, and the elements are displayed on the console.
The list is iterated over, twice, and elements of the first and next concurrent position are compared.
If they match, that element is considered as a duplicate.
It is displayed on the console.
- Related Questions & Answers
- Python program to print the elements of an array in reverse order
- Python program to print the elements of an array present on odd position
- Python program to print the elements of an array present on even position
- C Program to delete the duplicate elements in an array
- Python program to left rotate the elements of an array
- Python program to right rotate the elements of an array
- How to duplicate elements of an array in the same array with JavaScript?
- C# program to find all duplicate elements in an integer array
- How to remove duplicate elements of an array in java?
- Python program to print all distinct elements of a given integer array.
- Program to print Sum Triangle of an array.
- Python program to sort the elements of an array in ascending order
- Python program to sort the elements of an array in descending order
- Removing duplicate elements from an array in PHP
- Python program to Mark duplicate elements in string
Advertisements