🐍 Flatten a List of Lists

April 08, 2022 09:08 • Category: Code Bytes

A quick way to flatten a list of lists using only the standard library.

import itertools
l = [ [1, 2, 3], [4, 5, 6] ]
[i for i in itertools.chain.from_iterable(l)]
>>[1, 2, 3, 4, 5, 6]