diff --git a/strings/remove_duplicate.py b/strings/remove_duplicate.py index 5ab0e9962752..7e58875b22c1 100644 --- a/strings/remove_duplicate.py +++ b/strings/remove_duplicate.py @@ -1,3 +1,5 @@ +from collections import OrderedDict + def remove_duplicates(sentence: str) -> str: """ Remove duplicates from sentence @@ -6,7 +8,7 @@ def remove_duplicates(sentence: str) -> str: >>> remove_duplicates("Python is great and Java is also great") 'Java Python also and great is' """ - return " ".join(sorted(set(sentence.split()))) + return " ".join(list(OrderedDict.fromkeys(sentence.split()))) if __name__ == "__main__":