Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > concatenate the elements in each list of a list of lists

Reply
Thread Tools

concatenate the elements in each list of a list of lists

 
 
antar2
Guest
Posts: n/a
 
      07-23-2008
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 !

 
Reply With Quote
 
 
 
 
Chris
Guest
Posts: n/a
 
      07-23-2008
On Jul 23, 5:33*pm, antar2 <(E-Mail Removed)> 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)']
 
Reply With Quote
 
 
 
 
Michael Schneider
Guest
Posts: n/a
 
      07-23-2008
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
 
Reply With Quote
 
Niklas Norrthon
Guest
Posts: n/a
 
      07-23-2008
On 23 Juli, 17:33, antar2 <(E-Mail Removed)> 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 !


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

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Concatenate/De-Concatenate Carlos VHDL 10 10-24-2012 01:04 PM
common elements between list of lists and lists antar2 Python 2 07-17-2008 09:19 AM
List of lists of lists of lists... =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==?= Python 5 05-15-2006 11:47 AM
xsl:for-each for each 3 elements problem Tjerk Wolterink XML 3 11-03-2004 05:22 PM
Need to concatenate all files in a dir together into one file and read the first 225 characters from each file into another file. Tony Perl Misc 5 04-19-2004 03:28 PM



Advertisments