You have a nested list of items and need to find out how many layers of nesting there is.
For example
[1,2] = 1
[[1,2],[3,4]] = 2
[[[1,2],[3,4]],[[1,2],[3,4]]] = 3
def get_nesting_layers(lst):
for item in lst:
if type(item) == type([]):
return 1+get_nesting_layers(item)
return 1
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(get_nesting_layers([1,2]), 1)
test.assert_equals(get_nesting_layers([[1,2],[3,4]]), 2)
test.assert_equals(get_nesting_layers([[[1,2],[3,4]],[[1,2],[3,4]]]), 3)
def remove(integers, values): value_set = set(values) res = [] for x in integers: if x not in value_set: res += [x] return res
- def remove(integers, values):
- value_set = set(values)
return [x for x in integers if x not in value_set]- res = []
- for x in integers:
- if x not in value_set:
- res += [x]
- return res