On Aug 16, 6:47 am, Terry terry.yin...@gmail.com wrote:
Hi,
Is there a simple way (the pythonic way) to flatten a list of list?
rather than my current solution:
new_list=[]
for l in list_of_list:
new_list.extend(l)
or,
new_list=reduce(lambda x,y:x.extend(y), list_of_list)
br
On Sun, Aug 16, 2009 at 5:47 AM, Terryterry.yin...@gmail.com wrote:
Hi,
Is there a simple way (the pythonic way) to flatten a list of list?
rather than my current solution:
new_list=[]
for l in list_of_list:
new_list.extend(l)
or,
new_list=reduce(lambda x,y:x.extend(y), list_of_list
Hi,
Is there a simple way (the pythonic way) to flatten a list of list?
rather than my current solution:
new_list=[]
for l in list_of_list:
new_list.extend(l)
or,
new_list=reduce(lambda x,y:x.extend(y), list_of_list)
br, Terry
--
http://mail.python.org/mailman/listinfo/python-list
Terry wrote:
Is there a simple way (the pythonic way) to flatten a list of list?
This is probably the shortest it can get:
sum(list_of_lists, [])
Kind Regards,
M.F.
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, 16 Aug 2009 05:55:48 -0400, Chris Rebert wrote:
On Sun, Aug 16, 2009 at 5:47 AM, Terryterry.yin...@gmail.com wrote:
Hi,
Is there a simple way (the pythonic way) to flatten a list of list?
rather than my current solution:
new_list=[]
for l in list_of_list:
new_list.extend(l
On Sun, Aug 16, 2009 at 6:49 AM, Steven
D'Apranost...@remove-this-cybersource.com.au wrote:
On Sun, 16 Aug 2009 05:55:48 -0400, Chris Rebert wrote:
On Sun, Aug 16, 2009 at 5:47 AM, Terryterry.yin...@gmail.com wrote:
Hi,
Is there a simple way (the pythonic way) to flatten a list of list
On Sun, 16 Aug 2009 12:03:53 +0200, Michael Fötsch wrote:
Terry wrote:
Is there a simple way (the pythonic way) to flatten a list of list?
This is probably the shortest it can get:
sum(list_of_lists, [])
That's also O(N**2).
from timeit import Timer
setup = L = [ ([None]*5000) for x
,
Is there a simple way (the pythonic way) to flatten a list of list?
rather than my current solution:
new_list=[]
for l in list_of_list:
new_list.extend(l)
or,
new_list=reduce(lambda x,y:x.extend(y), list_of_list)
#only marginally better:
from operator import add
new_list
On Sun, 16 Aug 2009 02:47:42 -0700, Terry wrote:
Hi,
Is there a simple way (the pythonic way) to flatten a list of list?
rather than my current solution:
new_list=[]
for l in list_of_list:
new_list.extend(l)
I don't think that scales terribly well. In my testing, it performs about
On Sun, 16 Aug 2009 06:59:52 -0400, Chris Rebert wrote:
Surely that's going to be O(N**2)?
The OP asked for simple, not best, most proper, or fastest. My
comment was intended to mean that the code was marginally *simpler*, not
faster.
Fair enough, but he also asked for Pythonic, and while
On Sun, Aug 16, 2009 at 7:31 AM, Steven
D'Apranost...@remove-this-cybersource.com.au wrote:
On Sun, 16 Aug 2009 06:59:52 -0400, Chris Rebert wrote:
Surely that's going to be O(N**2)?
The OP asked for simple, not best, most proper, or fastest. My
comment was intended to mean that the code was
Chris Rebert:
The OP asked for simple, not best, most proper, or fastest. My
comment was intended to mean that the code was marginally *simpler*,
not faster.
Yep, the OP has asked for simple code. But often this is not the right
way to solve this situation. A better way is to create (or copy)
Steven D'Aprano wrote:
On Sun, 16 Aug 2009 02:47:42 -0700, Terry wrote:
Is there a simple way (the pythonic way) to flatten a list of list?
Chris' suggestion using itertools seems pretty good:
from timeit import Timer
setup = \\
... L = [ [None]*5000 for _ in xrange(%d) ]
... from itertools
On Aug 16, 1:25 pm, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
...
Chris' suggestion using itertools seems pretty good:
from timeit import Timer
setup = \\
... L = [ [None]*5000 for _ in xrange(%d) ]
... from itertools import chain
...
On 8/16/2009 5:47 AM Terry apparently wrote:
Is there a simple way (the pythonic way) to flatten a list of list?
rather than my current solution:
new_list=[]
for l in list_of_list:
new_list.extend(l)
new_list = list(xi for lst in list_of_list for xi in lst)
hth,
Alan Isaac
--
http
Terry terry.yin...@gmail.com writes:
Is there a simple way (the pythonic way) to flatten a list of list?
rather than my current solution:
new_list=[]
for l in list_of_list:
new_list.extend(l)
from itertools import chain
new_list = list(chain(list_of_list))
--
http://mail.python.org
16 matches
Mail list logo