← Back to challenges

Multidimensional List Into Single Dimensional List

PythonHardrecursionarrays

Instructions

Create a function that takes a multi-dimensional list and converts it (recursively) into a single-dimensional list and returns it. Use a RECURSIVE approach.

Examples

flatten([[17.2, 5, "code"]]) ➞ [17.2, 5, "code"]

flatten([[[[[2, 14, "rubber"]]], 2, 3, 4]])) ➞ [2, 14, "rubber", 2, 3, 4]

flatten([["dimension"]]) ➞ ["dimension"]

Notes

  • Input contains at least one element.
  • The use of built-in methods is discouraged.
  • A similar version of this challenge can be found here.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.