concatenate the elements in each list of a list of lists

Chris cwitts at gmail.com
Wed Jul 23 12:42:06 EDT 2008


On Jul 23, 5:33 pm, antar2 <desoth... at yahoo.com> wrote:
> I already asked a similar question, but encounter problems with
> python...
> How can I concatenate the elements in each list of a list of lists
>
> list_of_listsA =
>
> [['klas*', '*', '*'],
> ['mooi*', '*', '*', '*'],
> ['arm*', '*', '*(haar)']]
>
> wanted result:
>
> list_of_listsA =
>
> [['klas* * *']
> ['mooi* * * *']
> ['arm* * *(haar)']]
>
> Thanks a lot !

Nice and easy. :)

>>> list_of_listsA = [['klas*', '*', '*'],
['mooi*', '*', '*', '*'],
['arm*', '*', '*(haar)']]
>>> [' '.join(l) for l in list_of_listsA]
['klas* * *', 'mooi* * * *', 'arm* * *(haar)']



More information about the Python-list mailing list