Post

PythonPython

k
kumar san

Posted on 29th March 2024|14 views

0
votes

Python Flatten List Of Lists

How to flatten a list of lists in python?

Answers
P
sri kanth

Posted on 29th March 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