Menu

gitpiper

flatten python Code Snippet in 2022

listintermediate

Last Updated: 26 November 2022

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]

python snippet similar to flatten For You in November 2022

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2022 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️