import itertools def flatten(l): """e.g., l = [[-44, 68], [-4, 108], [0, 112], [-48, 64]]""" return list(itertools.chain.from_iterable(l))
l = [[-44, 68], [-4, 108], [0, 112], [-48, 64]]answer = [i for j in l for i in j]print(answer)- import itertools
- def flatten(l):
- """e.g., l = [[-44, 68], [-4, 108], [0, 112], [-48, 64]]"""
- return list(itertools.chain.from_iterable(l))
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(solution.flatten([[-44, 68], [-4, 108], [0, 112], [-48, 64]]), [-44, 68, -4, 108, 0, 112, -48, 64] )
- 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(1 + 1, 2)- test.assert_equals(solution.flatten([[-44, 68], [-4, 108], [0, 112], [-48, 64]]), [-44, 68, -4, 108, 0, 112, -48, 64]
- )