Skip to main content

flatten

Accepts a list and recursively flattens the contained list items. The final result is a list that contains non-list items only. Multiple lists can also be given as arguments.

flatten(listOfLists)
# Or
flatten(...args)

Parameters#

  • listOfLists: A list of lists to flatten
  • args: list arguments to be flattened

Returns#

  • Flattened list with only non-list items

Example#

# Merging two or more list items togetherprint(flatten([  [1, 2, 3],  [4, 5, 6]]))# prints [1, 2, 3, 4, 5, 6]
# Giving multiple lists as argumentsprint(flatten([1, 2], [3, 4]))# prints [1, 2, 3, 4]