472,373 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,373 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 2606
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 = ,,]...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

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.