From 76851cf664281495bbff71fc1ef2667607edaab3 Mon Sep 17 00:00:00 2001 From: Subhobhai Date: Sat, 18 Oct 2025 20:10:41 +0530 Subject: [PATCH 1/2] Improve doctest coverage for remove_duplicates function Contributes to #9943 - Added comprehensive doctests covering edge cases - Added tests for empty strings, single words, all duplicates - Added tests for mixed case, numbers, and special characters - Improved documentation with better examples --- strings/remove_duplicate.py | 55 +++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/strings/remove_duplicate.py b/strings/remove_duplicate.py index 5ab0e9962752..af656480f644 100644 --- a/strings/remove_duplicate.py +++ b/strings/remove_duplicate.py @@ -1,10 +1,53 @@ def remove_duplicates(sentence: str) -> str: """ - Remove duplicates from sentence - >>> remove_duplicates("Python is great and Java is also great") - 'Java Python also and great is' - >>> remove_duplicates("Python is great and Java is also great") - 'Java Python also and great is' + Remove duplicates from sentence and return words in sorted order + + Args: + sentence: Input string containing words separated by spaces + + Returns: + String with unique words sorted alphabetically + + Examples: + Basic functionality: + >>> remove_duplicates("Python is great and Java is also great") + 'Java Python also and great is' + + Multiple spaces handling: + >>> remove_duplicates("Python is great and Java is also great") + 'Java Python also and great is' + + Edge cases: + >>> remove_duplicates("") + '' + + >>> remove_duplicates(" ") + '' + + >>> remove_duplicates("hello") + 'hello' + + >>> remove_duplicates("hello hello hello") + 'hello' + + Mixed case (case sensitive): + >>> remove_duplicates("Python python PYTHON") + 'PYTHON Python python' + + Numbers and special characters: + >>> remove_duplicates("1 2 3 1 2 3") + '1 2 3' + + >>> remove_duplicates("hello world hello world!") + 'hello world world!' + + Single character words: + >>> remove_duplicates("a b c a b c") + 'a b c' + + Mixed content: + >>> remove_duplicates("The quick brown fox jumps over the lazy dog") + 'The brown dog fox jumps lazy over quick the' """ return " ".join(sorted(set(sentence.split()))) @@ -12,4 +55,4 @@ def remove_duplicates(sentence: str) -> str: if __name__ == "__main__": import doctest - doctest.testmod() + doctest.testmod() \ No newline at end of file From b1b27f07383953e6ae8a1fa9d2598962d8c3f45f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 18 Oct 2025 14:41:11 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/remove_duplicate.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/strings/remove_duplicate.py b/strings/remove_duplicate.py index af656480f644..5b3704f1a69f 100644 --- a/strings/remove_duplicate.py +++ b/strings/remove_duplicate.py @@ -1,50 +1,50 @@ def remove_duplicates(sentence: str) -> str: """ Remove duplicates from sentence and return words in sorted order - + Args: sentence: Input string containing words separated by spaces - + Returns: String with unique words sorted alphabetically - + Examples: Basic functionality: >>> remove_duplicates("Python is great and Java is also great") 'Java Python also and great is' - + Multiple spaces handling: >>> remove_duplicates("Python is great and Java is also great") 'Java Python also and great is' - + Edge cases: >>> remove_duplicates("") '' - + >>> remove_duplicates(" ") '' - + >>> remove_duplicates("hello") 'hello' - + >>> remove_duplicates("hello hello hello") 'hello' - + Mixed case (case sensitive): >>> remove_duplicates("Python python PYTHON") 'PYTHON Python python' - + Numbers and special characters: >>> remove_duplicates("1 2 3 1 2 3") '1 2 3' - + >>> remove_duplicates("hello world hello world!") 'hello world world!' - + Single character words: >>> remove_duplicates("a b c a b c") 'a b c' - + Mixed content: >>> remove_duplicates("The quick brown fox jumps over the lazy dog") 'The brown dog fox jumps lazy over quick the' @@ -55,4 +55,4 @@ def remove_duplicates(sentence: str) -> str: if __name__ == "__main__": import doctest - doctest.testmod() \ No newline at end of file + doctest.testmod()