Intermediate
Flatten nested lists
Write flatten(data) that takes a list that may contain other lists or tuples (to any depth) and returns one flat list in the original order.
Strings count as single items: flatten(["ab", ["cd"]]) is ["ab", "cd"], not individual letters.
What Check tests
- Flattens several levels
- Strings stay whole
- Tuples are flattened too
- Empty lists
- The input is not changed
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.