Skip to content

Commit 778a457

Browse files
committed
find duplicate problem
1 parent 6d3a97c commit 778a457

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

DataStructures/FindDuplicates.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def find_duplicates(input_list):
2+
element_count = {}
3+
duplicates = []
4+
5+
for item in input_list:
6+
if item in element_count:
7+
element_count[item] +=1
8+
else:
9+
element_count[item] = 1
10+
11+
for item, count in element_count.items():
12+
if count > 1:
13+
duplicates.append(item)
14+
return duplicates
15+
16+
17+
input_list = [1, 2, 3, 4, 5, 3, 2, 6, 7, 8, 1]
18+
duplicates = find_duplicates(input_list)
19+
print("Duplicates in the list:", duplicates)

0 commit comments

Comments
 (0)