Simple question of python. How to convert pseudo-matrix to list?

I have this:
>>> list = [[‘a1’, ‘a2’], [‘b1’, ‘b2’], [‘c1’, ‘c2’]]

So if I print:
>>> print(list)
[[‘a1’, ‘a2’], [‘b1’, ‘b2’], [‘c1’, ‘c2’]]

But I want this:
>>> print(list)
[‘a1’, ‘a2’, ‘b1’, ‘b2’, ‘c1’, ‘c2’]

I know if I do this:
>>> list2 = []
>>> for a in list:
… for b in a:
… list2.append(b)

I have this:
>>> print(list2)
[‘a1’, ‘a2’, ‘b1’, ‘b2’, ‘c1’, ‘c2’]

But how can I do this in a simpler way?
Preferably on one line?

Hi,

Is this what you are looking for? :slight_smile:

lst = [[‘a1’, ‘a2’], [‘b1’, ‘b2’], [‘c1’, ‘c2’]]

new_list = [x for y in lst for x in y]

Python List Comprehension

Yeah @jcue, worked very well :). Thank you very much. :smiley:
The line just got a little big:

if len(self.listverts) >=2 and self.geom2 not in [x for y in [a.verts[:] for a in self.listverts[-2].link_edges] for x in y]:                                                         
      self.bm.edges.new((self.listverts[-1], self.listverts[-2]))

But it worked.