Files
30-seconds-of-code/snippets/flatten.md
Isabelle Viktoria Maciohsek cbc78ee450 Bake dates into snippets
2021-06-13 19:38:10 +03:00

372 B

title, tags, firstSeen, lastUpdated
title tags firstSeen lastUpdated
flatten list,intermediate 2019-09-19T15:46:10+03:00 2020-11-02T19:27:53+02:00

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]