Skip to content

Refactor remove duplicates to more pythonic #2093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@
* [Scc Kosaraju](https://github.com/TheAlgorithms/Python/blob/master/graphs/scc_kosaraju.py)
* [Tarjans Scc](https://github.com/TheAlgorithms/Python/blob/master/graphs/tarjans_scc.py)

## Greedy Method
* [Greedy Knapsack](https://github.com/TheAlgorithms/Python/blob/master/greedy_method/greedy_knapsack.py)
* [Test Knapsack](https://github.com/TheAlgorithms/Python/blob/master/greedy_method/test_knapsack.py)

## Hashes
* [Chaos Machine](https://github.com/TheAlgorithms/Python/blob/master/hashes/chaos_machine.py)
* [Enigma Machine](https://github.com/TheAlgorithms/Python/blob/master/hashes/enigma_machine.py)
Expand Down
10 changes: 2 additions & 8 deletions strings/remove_duplicate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Created by sarathkaul on 14/11/19
""" Created by sarathkaul on 14/11/19 """


def remove_duplicates(sentence: str) -> str:
Expand All @@ -7,13 +7,7 @@ def remove_duplicates(sentence: str) -> str:
>>> remove_duplicates("Python is great and Java is also great")
'Java Python also and great is'
"""
sen_list = sentence.split(" ")
check = set()

for a_word in sen_list:
check.add(a_word)

return " ".join(sorted(check))
return " ".join(sorted(set(sentence.split(" "))))


if __name__ == "__main__":
Expand Down