Python | Program to print duplicates from a list of integer Method 2: Using a single for loop

preview_player
Показать описание
# Python program to print duplicates from
# a list of integers
lis = [1, 2, 1, 2, 3, 4, 5, 1, 1, 2, 5, 6, 7, 8, 9, 9]

uniqueList = []
duplicateList = []

for i in lis:
if i not in uniqueList:
elif i not in duplicateList:

print(duplicateList)

Output

[1, 2, 5, 9]
Рекомендации по теме