> The first idea that comes to mind is reduce(lambda x, y: x + y,
> list_of_lists, [])
Which is not helping for arbitrary nested lists, as the OP wanted.
Diez
--
http://mail.python.org/mailman/listinfo/python-list
On Apr 21, 2:35 am, sturlamolden <[EMAIL PROTECTED]> wrote:
> This also shows how easy it is to boost the performance of Python code
> using Cython.
We can improve this further by getting rid of the tmp.append attribue
lookup:
cdef _flatten(lst, append):
for elem in lst:
if type(elem
On Apr 21, 12:25 am, Zethex <[EMAIL PROTECTED]> wrote:
> Anyway the amount of [[]] do increase over time.
You can flatten a nested list using a closure and recursion:
def flatten(lst):
tmp = []
def _flatten(lst):
for elem in lst:
if type(elem) != list:
On 2008-04-20, Zethex <[EMAIL PROTECTED]> wrote:
> Im a bit new to python. Anyway working on a little project of mine and i
> have nested lists
What you want to do is usually called "flattening".
http://mail.python.org/pipermail/tutor/2001-January/002914.html
http://aspn.activestate.com/ASPN/Co
On Apr 20, 6:50 pm, Jason Scheirer <[EMAIL PROTECTED]> wrote:
> On Apr 20, 3:25 pm, Zethex <[EMAIL PROTECTED]> wrote:
>
>
>
> > Im a bit new to python. Anyway working on a little project of mine and i
> > have nested lists
>
> > ie
>
> > Answer = [['computer', 'radeon', 'nvidia'], ['motherboard',
On Apr 20, 3:25 pm, Zethex <[EMAIL PROTECTED]> wrote:
> Im a bit new to python. Anyway working on a little project of mine and i
> have nested lists
>
> ie
>
> Answer = [['computer', 'radeon', 'nvidia'], ['motherboard', 'asus']]
>
> and so forth..,
> Anyway the amount of [[]] do increase over time
On Apr 21, 12:25 am, Zethex <[EMAIL PROTECTED]> wrote:
> Anyway the amount of [[]] do increase over time. Im just wondering is there
> a simple way to add these together so they become 1 simple list, so it would
> be ['computer''asus'] etc without the nested list. Its random the
> amount eac
Im a bit new to python. Anyway working on a little project of mine and i
have nested lists
ie
Answer = [['computer', 'radeon', 'nvidia'], ['motherboard', 'asus']]
and so forth..,
Anyway the amount of [[]] do increase over time. Im just wondering is there
a simple way to add these together so