Home My space log
Language EN (English)

Flatten a list

Python Advanced astronaut ages teen+

The problem

Write a function flatten(items). The list items can hold numbers and also other lists, and those lists can hold lists too, as deep as you like. Give back one flat list with all the numbers in the same order. Example: flatten([1, [2, [3]], 4]) gives [1, 2, 3, 4].

You will practice: lists inside lists, isinstance, recursion (a function calling itself)

Mode

Press Tab to indent. Press Esc and then Tab to move on to the next button.

Your code runs in your browser. We do not receive it or save it. Python is downloaded from cdn.jsdelivr.net the first time you run it (about 10 MB).

Test results

      What your code printed