Ad

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
Code
Diff
  • 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