Post

PythonPython

k
kumar san

Posted on 28th February 2024|13 views

0
votes

Python Flatten List Of Lists

How to flatten a list of lists in python?

Answers
P
sri kanth

Posted on 28th February 2024

You can understand it by this example

list_of_lists = [[5, 6], [7, 8]]

chain_object = itertools.chain.from_iterable(list_of_lists)

flattened_li = list(chain_object)

Convert to list to flatten

print(flattened_li)

Output: [5, 6, 7, 8]

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos