Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 22da3c2

Browse files
authoredOct 7, 2024··
remove_duplicate.py
1 parent dba8eec commit 22da3c2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed
 

‎strings/remove_duplicate.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from collections import OrderedDict
2+
13
def remove_duplicates(sentence: str) -> str:
24
"""
35
Remove duplicates from sentence
@@ -6,7 +8,7 @@ def remove_duplicates(sentence: str) -> str:
68
>>> remove_duplicates("Python is great and Java is also great")
79
'Java Python also and great is'
810
"""
9-
return " ".join(sorted(set(sentence.split())))
11+
return " ".join(list(OrderedDict.fromkeys(sentence.split())))
1012

1113

1214
if __name__ == "__main__":

0 commit comments

Comments
 (0)
Please sign in to comment.