how to unpack list of lists into a new list using for/while loops

Viewed 21

I'm a paython new learner and I have an assignment to extract all elements from a simple list (any depth) and unpack it into a new list of simple elements.

Something like this:

lst = [1, 2, [3, 4, [5, 6, 7]]]

new_lst = [1, 2, 3, 4, 5, 6, 7]

Catch is, I can't use functions to do it directly.. can only use loops (for/while) or conditional statements (if elif else) or python functions like "append".

Any ideas?

0 Answers
Related