Академический Документы
Профессиональный Документы
Культура Документы
Positional arguments:
my_list - list, this is the original input list.
depth - int, depth of "flattening" of the list.
Returns:
list - flattened or not according to depth
"""
if depth > 0:
result = []
for elem in my_list:
if isinstance(elem, list):
result += flatten(elem, depth-1)
else:
result += [elem]
return result
else:
return my_list