concatenate the elements in each list of a list of lists

A

antar2

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 !
 
C

Chris

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)']
 
M

Michael Schneider

Am Wed, 23 Jul 2008 08:33:57 -0700 wrote antar2:
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 !

Hello,

maybe this will help:

In [5]: list_of_listsA = [['klas*', '*', '*'], ['mooi*', '*', '*', '*'],
['arm*', '* ', '*(haar)']]
In [6]: s = ""
In [7]: print [[s.join(item)] for item in list_of_listsA]
[['klas***'], ['mooi****'], ['arm** *(haar)']]

regards
Michael
 
N

Niklas Norrthon

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 !

wanted_result = [[item] for item in map(' '.join, list_of_listsA)]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top