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)
#
ParameterslistOfLists
: Alist
oflist
s to flattenargs
: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]