diff --git a/kyu_4/strings_mix/solution.py b/kyu_4/strings_mix/solution.py index a73966a0bfa..66b621badd6 100644 --- a/kyu_4/strings_mix/solution.py +++ b/kyu_4/strings_mix/solution.py @@ -1,5 +1,6 @@ """ -Solution for -> Strings Mix +Solution for -> Strings Mix. + Created by Egor Kostan. GitHub: https://github.com/ikostan """ @@ -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). @@ -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 + 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: """ @@ -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 """