-
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) .describe("Example") def test_group(): .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])
Output:
-
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:]
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}