Hello, I have one trouble in my program I´m currently working on. I need to make a function, which flatten a list whom items can contain lists again, into a one simple list. Function gets a list as a parameter and I need to return new flattened list without changing the main one, using recursion.
This is my current attempt:
Thanks.
This is my current attempt:
result = []
def flatten(nested_list):
for i in nested_list:
if type(i) != list:
result.append(i)
else:
flatten(i)
return resultThe problem here is, as soon as I want to run this function again, it remembers the last result, what means that it appends everything at the end. But I want to make a new result, containing just a simple list of current nested one. How can I remove last result when calling function again?Thanks.
