convert list of lists to list

Peter Otten __peter__ at web.de
Tue Jul 22 11:31:10 EDT 2008


antar2 wrote:

> Is there a way to convert list_of_listsA to list_of_listsB, where one
> list in listof lists A is one element of listB?
> 
> list_of_listsA:
> [['klas*', '*', '*'],
> ['mooi*', '*', '*', '*'],
> ['koe'],
> ['arm*', '*', '*(haar)'],
> ['groei*', '*', '*', '*', '*']]
> 
> listB:
> ['klas* * *', 'mooi* * * *, 'koe',  'arm* * * (haar)',  'groei* * * *
> *']

>>> outer = [['klas*', '*', '*'],
... ['mooi*', '*', '*', '*'],
... ['koe'],
... ['arm*', '*', '*(haar)'],
... ['groei*', '*', '*', '*', '*']]
>>> [" ".join(inner) for inner in outer]
['klas* * *', 'mooi* * * *', 'koe', 'arm* * *(haar)', 'groei* * * * *']

Peter



More information about the Python-list mailing list