Docsity

Python program to display duplicates from a list of integers, Assignments of Computer science

Toggle sidebar
bg1
Display duplicates from a list of
integers
Aim:
Write a python program to display duplicates from a list
of integers.
Algorithm:
1. Start
2. Get a list from the user and save it in variable โ€˜aโ€™.
3. Initialise l as an empty list.
4. Traverse the list using a for loop with iterating
variable i. Execute steps
5 to 7 repeatedly.
5. Check whether i is not an element of l.
6. If True, then add i to l and check whether the count
of i is greater than
1.
7. If True, display i.
8. Stop
Program:
a=eval(input('Enter a list:\t'))
l=[ ]
print('Elements with count more than one:')
for i in a:
if i not in l:
pf2

Partial preview of the text

Download Python program to display duplicates from a list of integers and more Assignments Computer science in PDF only on Docsity!

Display duplicates from a list of

integers

Aim:

Write a python program to display duplicates from a list of integers.

Algorithm:

  1. Start
  2. Get a list from the user and save it in variable โ€˜aโ€™.
  3. Initialise l as an empty list.
  4. Traverse the list using a for loop with iterating variable i. Execute steps 5 to 7 repeatedly.
  5. Check whether i is not an element of l.
  6. If True, then add i to l and check whether the count of i is greater than
  7. If True, display i.
  8. Stop

Program:

a=eval(input('Enter a list:\t')) l=[ ] print('Elements with count more than one:') for i in a: if i not in l:

l.append(i) if a.count(i)>1: print(i)

Output:

Enter a list: [9,4,4,5,6,3,3,3,8,2,2,1] Elements with count more than one: 4 3 2

Result

The python program to display duplicates from a list of integers is successfully completed and the output is verified.