From cc5ac75f45bab5177aa582d42b2c1ba4da3413b9 Mon Sep 17 00:00:00 2001 From: Egor Kostan <20955183+ikostan@users.noreply.github.com> Date: Tue, 17 Dec 2024 06:22:44 -0800 Subject: [PATCH] # String subpattern recognition III --- kyu_6/string_subpattern_recognition_3/__init__.py | 1 + .../string_subpattern_recognition_3/has_subpattern.py | 8 +++----- .../test_has_subpattern.py | 10 +++++----- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/kyu_6/string_subpattern_recognition_3/__init__.py b/kyu_6/string_subpattern_recognition_3/__init__.py index e69de29bb2d..b63d54f57ea 100644 --- a/kyu_6/string_subpattern_recognition_3/__init__.py +++ b/kyu_6/string_subpattern_recognition_3/__init__.py @@ -0,0 +1 @@ +"""String subpattern recognition III.""" diff --git a/kyu_6/string_subpattern_recognition_3/has_subpattern.py b/kyu_6/string_subpattern_recognition_3/has_subpattern.py index 12cff1a2e0d..700d08cd958 100644 --- a/kyu_6/string_subpattern_recognition_3/has_subpattern.py +++ b/kyu_6/string_subpattern_recognition_3/has_subpattern.py @@ -1,5 +1,6 @@ """ -Solution for -> String subpattern recognition III +Solution for -> String subpattern recognition III. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -9,7 +10,7 @@ def has_subpattern(string: str) -> str: """ - String subpattern recognition III + String subpattern recognition III. Since there is no deterministic way to tell which pattern was really the original one among all the possible @@ -18,13 +19,11 @@ def has_subpattern(string: str) -> str: with sorted characters (you might consider this case as an edge case, with the subpattern being repeated only once and thus equalling the original input string). - :param string: :return: """ # get unique chars filtered_chars: set = set(list(string)) - # set counter for each char in string char_counter: dict = {} for char in filtered_chars: @@ -32,7 +31,6 @@ def has_subpattern(string: str) -> str: # get sorted counters sorted_char_counters: list = sorted(set(char_counter.values())) - # find common greatest divider: divider = sorted_char_counters[0] if len(sorted_char_counters) > 1: diff --git a/kyu_6/string_subpattern_recognition_3/test_has_subpattern.py b/kyu_6/string_subpattern_recognition_3/test_has_subpattern.py index 28d6c90d817..634dd5315dd 100644 --- a/kyu_6/string_subpattern_recognition_3/test_has_subpattern.py +++ b/kyu_6/string_subpattern_recognition_3/test_has_subpattern.py @@ -1,5 +1,6 @@ """ -Test for -> String subpattern recognition III +Test for -> String subpattern recognition III. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -31,12 +32,11 @@ name='Source/Kata') # pylint: enable-msg=R0801 class HasSubpatternTestCase(unittest.TestCase): - """ - Testing 'has_subpattern' function - """ + """Testing 'has_subpattern' function.""" + def test_has_subpattern(self): """ - Verify that 'has_subpattern' function + Verify that 'has_subpattern' function. Return a subpattern with sorted characters, otherwise return the base string with sorted