By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,479 Members | 1,256 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,479 IT Pros & Developers. It's quick & easy.

concatenate the elements in each list of a list of lists

P: n/a
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 !

Jul 23 '08 #1
Share this Question
Share on Google+
3 Replies

P: n/a
On Jul 23, 5:33*pm, antar2 <desoth...@yahoo.comwrote:
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)']
Jul 23 '08 #2

P: n/a
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
Jul 23 '08 #3

P: n/a
On 23 Juli, 17:33, antar2 <desoth...@yahoo.comwrote:
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)]
Jul 23 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.