Assuming input:
[1, [3, 6], 9, [2, [1, 3]], [4, [1], 5], [6], 1, [[2]]]
Expected output:
[1,1,1,1,2,2,3,3,4,5,6,6,9]
How do I flatten the list without removing the duplicates?
My current situation
def flatten(lst):
nlist = []
for item in lst:
nlist = nlist + [item]
return nlist
My initial thought was that to re-add the elements into a new list to get the expected output. However it did not went well, I am getting
What i get:
[1, [3, 6], 9, [2, [1, 3]], [4, [1], 5], [6], 1, [[2]]]
I am using IDLE 3.3, and I am totally a newbie, if it is possible please tell me how to define it manually instead of using built in functions, meaning using recursive or iterative method. thanks guys!!