diff --git a/kyu_4/range_extraction/solution.py b/kyu_4/range_extraction/solution.py index 8db916961bd..fe5bfdb3e06 100644 --- a/kyu_4/range_extraction/solution.py +++ b/kyu_4/range_extraction/solution.py @@ -22,10 +22,11 @@ def solution(args: list) -> str: continue # case 2 - result = case_2(a, i, current, result) + result = case_2(a=a, i=i, current=current, result=result) # case 3 - result = case_3(args, a, i, current, result) + if i == len(args) - 1 and not current[2]: + result = case_3(args=args, a=a, i=i, current=current, result=result) # case 4 if i == len(args) - 1 and current[-1] != a and current[2]: @@ -44,20 +45,19 @@ def case_3(args: list, a: int, i: int, current: list, result: str) -> str: :param result: :return: """ - if i == len(args) - 1 and not current[2]: - if current[1] + 1 == a: - current[1] = a + if current[1] + 1 == a: + current[1] = a - result += str(current[0]) - if abs(current[1] - current[0]) >= 2: - result += '-' + str(current[1]) - elif current[0] != current[1]: - result += ',' + str(current[1]) + result += str(current[0]) + if abs(current[1] - current[0]) >= 2: + result += '-' + str(current[1]) + elif current[0] != current[1]: + result += ',' + str(current[1]) return result -def case_2(a: int, i: int, current: list, result: str) -> str: +def case_2(**kwargs) -> str: """ Case #2 :param i: @@ -66,6 +66,12 @@ def case_2(a: int, i: int, current: list, result: str) -> str: :param result: :return: """ + + a: int = kwargs['a'] + i: int = kwargs['i'] + current: list = kwargs['current'] + result: str = kwargs['result'] + if a == current[1] + 1: current[1] = a current[2] = False