Is there a way to convert list_of_listsA to list_of_listsB, where one
list in listof lists A is one element of listB?
list_of_listsA:
[['klas*', '*', '*'],
['mooi*', '*', '*', '*'],
['koe'],
['arm*', '*', '*(haar)'],
['groei*', '*', '*', '*', '*']]
listB:
['klas* * *', 'mooi* * * *, 'koe', 'arm* * * (haar)', 'groei* * * *
*']
Thankx! 4 2001
antar2 wrote:
Is there a way to convert list_of_listsA to list_of_listsB, where one
list in listof lists A is one element of listB?
list_of_listsA:
[['klas*', '*', '*'],
['mooi*', '*', '*', '*'],
['koe'],
['arm*', '*', '*(haar)'],
['groei*', '*', '*', '*', '*']]
listB:
['klas* * *', 'mooi* * * *, 'koe', 'arm* * * (haar)', 'groei* * * *
*']
if there's only one level of recursion, and the lists aren't too long,
you can simply do:
sum(list_of_lists, [])
(this has quadratic performance, so don't use it for large structures)
for recursive solutions, see: http://www.google.com/search?q=flatten+lists+python
</F>
antar2 wrote:
Is there a way to convert list_of_listsA to list_of_listsB, where one
list in listof lists A is one element of listB?
list_of_listsA:
[['klas*', '*', '*'],
['mooi*', '*', '*', '*'],
['koe'],
['arm*', '*', '*(haar)'],
['groei*', '*', '*', '*', '*']]
listB:
['klas* * *', 'mooi* * * *, 'koe', 'arm* * * (haar)', 'groei* * * *
*']
>>outer = [['klas*', '*', '*'],
.... ['mooi*', '*', '*', '*'],
.... ['koe'],
.... ['arm*', '*', '*(haar)'],
.... ['groei*', '*', '*', '*', '*']]
>>[" ".join(inner) for inner in outer]
['klas* * *', 'mooi* * * *', 'koe', 'arm* * *(haar)', 'groei* * * * *']
Peter
Fredrik Lundh wrote:
>['klas* * *', 'mooi* * * *, 'koe', 'arm* * * (haar)', 'groei* * * * *']
if there's only one level of recursion, and the lists aren't too long,
you can simply do:
sum(list_of_lists, [])
oops. that's what you get for taking the subject line too literally...
On Jul 22, 8:25*am, Fredrik Lundh <fred...@pythonware.comwrote:
if there's only one level of recursion, and the lists aren't too long,
you can simply do:
* * *sum(list_of_lists, [])
(this has quadratic performance, so don't use it for large structures)
For linear performance, you can use itertools:
list(itertools.chain(*list_of_lists))
Raymond This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jochen Hub |
last post by:
Hi,
I am a real beginner in Python and I was wondering if there is a way to
convert a string (which contains a list) to a "real" list.
I need this since I would like to give a list as an...
|
by: Oliver Eichler |
last post by:
Hi,
I can find examples to convert lists into a list of tuples like:
>>> map(None,,)
but how is it done vice versa?
Oliver
|
by: flyaflya |
last post by:
a = "(1,2,3)"
I want convert a to tuple:(1,2,3),but tuple(a) return ('(', '1', ',',
'2', ',', '3', ')') not (1,2,3)
|
by: Andre Winarko |
last post by:
How do you convert a date dd/mm/yyyy from a .txt file
into mysql date
format when using LOAD DATA INFILE ?
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free,...
|
by: Cox |
last post by:
Hello:
My address jsmith435@cox.net is subscribed to at least the PHP General
mailing list. I have for days now been trying to unsubscribe from all PHP
mail lists. I have followed the...
|
by: comp.lang.tcl |
last post by:
My TCL proc, XML_GET_ALL_ELEMENT_ATTRS, is supposed to convert an XML
file into a TCL list as follows:
attr1 {val1} attr2 {val2} ... attrN {valN}
This is the TCL code that does this:
set...
|
by: rh0dium |
last post by:
Hi all,
I am using pexpect to drive another tool. Some of the data I get back
would be better suited as a list and I want to know a simple way to
parse the data to push it into a list.
For...
|
by: pereges |
last post by:
Hi, I am wondering which of the two data structures (link list or
array) would be better in my situation. I have to create a list of
rays for my ray tracing program.
the data structure of ray...
|
by: Fred Mellender |
last post by:
I am trying to use reflection to output the fields (names and values) of an
arbitrary object -- an object dump to a TreeView.
It works pretty well, but I am having trouble with generic lists,...
|
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...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |