Decomposition is the key to reuse and healthy code support.
from typing import List def greatest(lst: List[int]) -> int: str_lst = [str(n) for n in lst] sorted_lst = sorted(str_lst, reverse=True) result = int(''.join(sorted_lst)) return result
def greatest(lst):return int(''.join(sorted([str(n) for n in lst], reverse=True)))- from typing import List
- def greatest(lst: List[int]) -> int:
- str_lst = [str(n) for n in lst]
- sorted_lst = sorted(str_lst, reverse=True)
- result = int(''.join(sorted_lst))
- return result
import codewars_test as test # TODO Write tests import solution # or from solution import example # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(greatest([1, 2, 3, 4, 5, 6, 7, 8, 9]), 987654321) test.assert_equals(greatest([1, 9, 2, 8, 3, 7, 4, 6, 5]), 987654321)
- import codewars_test as test
- # TODO Write tests
- import solution # or from solution import example
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
test.assert_equals(greatest([1,2,3,5,5,3,9,0,3,4,3]), 95543333210)test.assert_equals(greatest([6,6,6,7,7,0]), 776660)- test.assert_equals(greatest([1, 2, 3, 4, 5, 6, 7, 8, 9]), 987654321)
- test.assert_equals(greatest([1, 9, 2, 8, 3, 7, 4, 6, 5]), 987654321)