Menu

gitpiper

flatten python Code Snippet in 2024

listintermediate

Last Updated: 20 March 2024

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 March 2024

Subscribe to our Newsletter

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

© 2024 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! ✌️