You can flatten a list in python using the following one-liner:
In the example above, l is the list of lists that is to be flattened.
The previous example can be rewritten to be more readable and will look like this:
You can wrap this functionality into a function if you prefer:
Got an article suggestion?
Let us know
BY
NC
SA
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.