Skip to content

Commit

Permalink
# String subpattern recognition III
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 17, 2024
1 parent b778a9a commit cc5ac75
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions kyu_6/string_subpattern_recognition_3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""String subpattern recognition III."""
8 changes: 3 additions & 5 deletions kyu_6/string_subpattern_recognition_3/has_subpattern.py
Original file line number Diff line number Diff line change
@@ -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
"""
Expand All @@ -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
Expand All @@ -18,21 +19,18 @@ 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:
char_counter[char] = string.count(char)

# 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:
Expand Down
10 changes: 5 additions & 5 deletions kyu_6/string_subpattern_recognition_3/test_has_subpattern.py
Original file line number Diff line number Diff line change
@@ -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
"""
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cc5ac75

Please sign in to comment.