Re: Nested lists, simple though

2008-04-21 Thread Diez B. Roggisch
> 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

Re: Nested lists, simple though

2008-04-20 Thread sturlamolden
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

Re: Nested lists, simple though

2008-04-20 Thread sturlamolden
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:

Re: Nested lists, simple though

2008-04-20 Thread Grant Edwards
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

Re: Nested lists, simple though

2008-04-20 Thread George Sakkis
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',

Re: Nested lists, simple though

2008-04-20 Thread Jason Scheirer
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

Re: Nested lists, simple though

2008-04-20 Thread sturlamolden
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

Nested lists, simple though

2008-04-20 Thread Zethex
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