Skip to content

Flatten a list of lists in Python

Advertisements

lst = [[1, 2, 3, 4], [5, 6, 7, 8]];
print [x for y in lst for x in y]

#[1, 2, 3, 4, 5, 6, 7, 8]
See also  Reverse a number including decimal points in Python

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.