Flatten a list of lists in Python

Welcome to a new Python code snippet. In this post, we are going to suggest a couple of methods to flatten a list of lists. The final output is going to be a one dimensional list. Let us take an example:

  • Using nested loops

  • Using list comprehensions

  • Using sum function

  • Using list extend

  • Using chain from itertools

  • Using chain.from_iterable

  • Using reduce, lambda

  • Using reduce, add operator

That is all. Thanks for visiting, for questions and feedback, please use the comments section below.

Tags:

Add a Comment

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