Editor settings

General settings

Save settings

Learn to program with Python

Flatten it out #

Write a function that takes a list as input and returns a new list with all the values flattened. The input list can contain non-list values, lists, or even nested lists. The goal is to create a single-level list containing all the values from the input list.


Tests #

  • flatten_list([5, 6, 7, 8]) should return [5, 6, 7, 8]
  • flatten_list([[1], [2], [3], [4]]) should return [1, 2, 3, 4]
  • flatten_list([1, [2, 3], [4, [5, 6]]]) should return [1, 2, 3, 4, 5, 6]
  • flatten_list([7, [8, 9, [10]], 11]) should return [7, 8, 9, 10, 11]
  • flatten_list(['a', ['b', ['c', 'd']]]) should return ['a', 'b', 'c', 'd']
Output will be displayed here