473,387 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

concatenate the elements in each list of a list of lists

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
3 2651
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Matthew Sims | last post by:
Python Newbie here. This is my first time learning object-oriented programming and trying to break out of the usual Korn/Perl/PHP style of programming. Having some difficulty understand some items....
24
by: Steven Bethard | last post by:
I think one of the biggest reasons we're having such problems coming to any agreement on decorator syntax is that each proposal makes a number of syntax decisions, not just one. For decorators, I...
8
by: Nickolay Kolev | last post by:
Hi all, I have a list whose length is a multiple of 3. I want to get a list of tuples each of which has 3 consecutive elements from the original list, thus packing the list into smaller...
0
by: Nick Heppleston | last post by:
I have a concatenation problem and I was wondering if somebody might be able to offer some help :-) I have the following table structure holding product long descriptions: Part...
8
by: Generic Usenet Account | last post by:
To settle the dispute regarding what happens when an "erase" method is invoked on an STL container (i.e. whether the element is merely removed from the container or whether it also gets deleted in...
34
by: Adam Hartshorne | last post by:
Hi All, I have the following problem, and I would be extremely grateful if somebody would be kind enough to suggest an efficient solution to it. I create an instance of a Class A, and...
1
by: Grzegorz ¦lusarek | last post by:
Hi all. I my application i have situation when i have some lists and i must get from lists common elements. Exacly i don't know how many list I have so at the moment of creation each of one I...
56
by: Zytan | last post by:
Obviously you can't just use a simple for loop, since you may skip over elements. You could modify the loop counter each time an element is deleted. But, the loop ending condition must be...
2
by: antar2 | last post by:
Hello, I am a beginner in python. following program prints the second element in list of lists 4 for the first elements in list 4 that are common with the elements in list 5 list4 = ,,]...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.