Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 53b7469

Browse files
author
Amogh Singhal
authored
Update remove_duplicates.py
1 parent 1ff5a1b commit 53b7469

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

‎remove_duplicates.py‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
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
1+
def remove_duplicates(arr):
2+
return list(dict.fromkeys(arr))
93

10-
result = remove_duplicates([1, 1, 2, 2, 3, 4, 5])
4+
result = remove_duplicates([0,0,0,1,1,2,2,3,4,5])
115
print(result) # [1, 2, 3, 4, 5]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /