Skip to content

Commit 77e54f9

Browse files
author
Amogh Singhal
authored
Create remove_duplicates.py
1 parent cb46cb8 commit 77e54f9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

remove_duplicates.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def remove_duplicates(num_array):
2+
d = dict()
3+
for idx in range(0, len(num_array)):
4+
if num_array[idx] in d.keys():
5+
num_array[idx] = 0
6+
d[num_array[idx]] = 1
7+
dedupe_array = [n for n in num_array if n != 0]
8+
return dedupe_array
9+
10+
result = remove_duplicates([1, 1, 2, 2, 3, 4, 5])
11+
print(result) # [1, 2, 3, 4, 5]

0 commit comments

Comments
 (0)