Flatten list
Flattens a list of lists once.
- Use a list comprehension to extract each value from sub-lists in order.
def flatten(lst): return [x for y in lst for x in y] flatten([[1, 2, 3, 4], [5, 6, 7, 8]]) # [1, 2, 3, 4, 5, 6, 7, 8]
Flattens a list of lists once.
def flatten(lst): return [x for y in lst for x in y] flatten([[1, 2, 3, 4], [5, 6, 7, 8]]) # [1, 2, 3, 4, 5, 6, 7, 8]
Returns every element that exists in any of the two lists once, after applying the provided function to each element of both.
Executes the provided function once for each list element, starting from the list's last element.
Flattens a list, by spreading its elements into a new list.
Deep flattens a list.