Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - unpack list of lists [duplicate]

Tags:

python

What is the cleanest way to implement the following:

list = [list1, list2, ...]
return [*list1, *list2, ...]

It looks like this syntax will be available in Python 3.5. In the meantime, what is your solution?

like image 543
Eric Kaschalk Avatar asked Nov 29 '22 23:11

Eric Kaschalk


1 Answers

This is commonly written as:

[x for l in list for x in l]
like image 60
Lynn Avatar answered Dec 05 '22 04:12

Lynn