Move History

Fork Selected
  • Code
    def spawn_to_range(a, v, r): return a[:(i := a.index(v))] + [v] * r + a[i + 1:]
    Test Cases
    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(spawn_to_range([0, 10, 20, 13], 13, 4), [0, 10, 20, 13, 13, 13, 13])
            test.assert_equals(spawn_to_range([0, 10, 12, 14], 10, 3), [0, 10, 10, 10, 12, 14])
    
  • Code
    • def spawn_to_range(a, v, r): i = a.index(v); return a[:i] + [v] * r + a[i + 1:]
    • def spawn_to_range(a, v, r): return a[:(i := a.index(v))] + [v] * r + a[i + 1:]