Skip to content
This repository was archived by the owner on May 7, 2023. It is now read-only.

Files

Latest commit

 

History

History
20 lines (16 loc) · 365 Bytes

flatten.md

File metadata and controls

20 lines (16 loc) · 365 Bytes
title type tags cover dateModified
Flatten list
snippet
list
jars-on-shelf
2020-11-02 19:27:53 +0200

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]