Python flatten list of lists into list
For scenarios where a function outputs a list, and that function is in a for loop or asyncio event loop, the final output will be a list of lists, like:
x = [[1,2,3], [4, 5, 6]]
This may be inconvenient for applications where a flattened list is required. The simplest and fastest way to flatten a list of lists in like:
import itertools
x = [[1,2,3], [4, 5, 6]]
x_flat = list(itertools.chain(*x))
which results in
[1, 2, 3, 4, 5, 6]