Command Palette

Search for a command to run...

Hectal
Phase 17: Interviews and Capstone
Python · Exercise 3 of 6 PreviousNext
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

  1. Flattens several levels
  2. Strings stay whole
  3. Tuples are flattened too
  4. Empty lists
  5. 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.