Skip to content

Commit

Permalink
Update solution.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 7, 2024
1 parent 76d6d86 commit 92ef00e
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions kyu_4/strings_mix/solution.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Solution for -> Strings Mix
Solution for -> Strings Mix.
Created by Egor Kostan.
GitHub: https://github.com/ikostan
"""
Expand All @@ -11,6 +12,8 @@

def mix(s1: str, s2: str) -> str:
"""
Mix function.
Given two strings s1 and s2, we want to visualize
how different the two strings are. We will only
take into account the lowercase letters (a to z).
Expand All @@ -30,28 +33,33 @@ def mix(s1: str, s2: str) -> str:

results: list = []
for key in keys:
if key in s2_results and key in s1_results:
if s1_results[key] == s2_results[key]:
results.append(f'=:{key * s1_results[key]}')
elif s1_results[key] > s2_results[key]:
results.append(f'1:{key * s1_results[key]}')
else:
results.append(f'2:{key * s2_results[key]}')
if (
key in s2_results
and key in s1_results
and s1_results[key] == s2_results[key]
):
results.append(f'=:{key * s1_results[key]}')
elif (
key in s2_results

Check notice on line 43 in kyu_4/strings_mix/solution.py

View check run for this annotation

codefactor.io / CodeFactor

kyu_4/strings_mix/solution.py#L43

Too many boolean expressions in if statement (6/5) (too-many-boolean-expressions)
and key in s1_results
and s1_results[key] > s2_results[key]
or (key not in s2_results or key not in s1_results)
and key in s1_results
):
results.append(f'1:{key * s1_results[key]}')
else:
if key in s1_results:
results.append(f'1:{key * s1_results[key]}')
else:
results.append(f'2:{key * s2_results[key]}')

results.append(f'2:{key * s2_results[key]}')
return '/'.join(sort_results(results))


def sort_results(results: list) -> list:
"""
Sorting results.
The results will be in decreasing order of their length
and when they have the same length sorted in ascending
lexicographic order (letters and digits - more precisely
sorted by code-point)
sorted by code-point).
:param results:
:return:
"""
Expand All @@ -76,7 +84,8 @@ def sort_results(results: list) -> list:

def get_counters(s: str) -> dict:
"""
Get counters
Get counters.
:param s: str
:return: dict
"""
Expand Down

0 comments on commit 92ef00e

Please sign in to comment.