Re: [Tutor] flattening a list

2005-01-22 Thread Orri Ganel
Jacob S. wrote: Ahh, my pitiful form of flattening a list that cheats... def flatten(li): li = str(li) li = li.replace("[","") li = li.replace("]","") li = li.replace("(","") li = li.replace(")","") li = "[%s]"%li return eval(li) It works! It's probably just a bit slower

Re: [Tutor] flattening a list

2005-01-22 Thread Jacob S.
Ahh, my pitiful form of flattening a list that cheats... def flatten(li): li = str(li) li = li.replace("[","") li = li.replace("]","") li = li.replace("(","") li = li.replace(")","") li = "[%s]"%li return eval(li) It works! It's probably just a bit slower. Jacob Schmidt

Re: [Tutor] flattening a list

2005-01-14 Thread Orri Ganel
One final note to wrap things up. I posted a slightly cleaner version of my code on the Python Cookbook, with a reference to the solutions of Gonçalo and Danny via the tutor archives here: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/363051 -- Email: singingxduck AT gmail DOT com AIM

Re: [Tutor] flattening a list

2005-01-13 Thread Chad Crabtree
You should post this on the Python Cookbook http://aspn.activestate.com/ASPN/Python/Cookbook/ Orri Ganel wrote > Bill Kranec wrote: > > > >> Hello, > > >> > >> I have a list of lists, for example [ [1,2] , [3,4] ], and I would > > >> like to pass all the elements of that list as arguments to a f

Re: [Tutor] flattening a list

2005-01-13 Thread Gonçalo Rodrigues
Chad Crabtree wrote: The only problem with this if it is to big or to deeply nested then it will overflow the stack? Danny Yoo has given a mind-blowing continuation implementation that will not overflow the stack. Below goes a recursive-iterator implementation. To avoid deep recursion the code

Re: [Tutor] flattening a list

2005-01-12 Thread Danny Yoo
> > def flatten(a): > >if not isinstance(a,(tuple,list)): return [a] > >if len(a)==0: return [] > >return flatten(a[0])+flatten(a[1:]) > The only problem with this if it is to big or to deeply nested then it > will overflow the stack? Yes, it can overflow in its current incarnation.

Re: [Tutor] flattening a list

2005-01-12 Thread Chad Crabtree
The only problem with this if it is to big or to deeply nested then it will overflow the stack? Mario Rol wrote: > nice and concise, found on comp.lang.python: > > def flatten(a): >if not isinstance(a,(tuple,list)): return [a] >if len(a)==0: return [] >return flatten(a[0])+flatten(a[

Re: [Tutor] flattening a list

2005-01-12 Thread Mario Rol
nice and concise, found on comp.lang.python: def flatten(a): if not isinstance(a,(tuple,list)): return [a] if len(a)==0: return [] return flatten(a[0])+flatten(a[1:]) _ Play online games with your friends with MSN Messenger h

Re: [Tutor] flattening a list

2005-01-12 Thread Orri Ganel
Bill Kranec wrote: Hello, I have a list of lists, for example [ [1,2] , [3,4] ], and I would like to pass all the elements of that list as arguments to a function (for example the intersection of all list elements). Is there a command in regular Python to do this? I would like to avoid the ha

Re: [Tutor] flattening a list

2005-01-11 Thread Marilyn Davis
On Wed, 12 Jan 2005 [EMAIL PROTECTED] wrote: > Quoting Bill Kranec <[EMAIL PROTECTED]>: > > > I have a list of lists, for example [ [1,2] , [3,4] ], and I would like > > to pass all the elements of that list as arguments to a function (for > > example the intersection of all list elements). Is t

Re: [Tutor] flattening a list

2005-01-11 Thread jfouhy
Quoting Bill Kranec <[EMAIL PROTECTED]>: > I have a list of lists, for example [ [1,2] , [3,4] ], and I would like > to pass all the elements of that list as arguments to a function (for > example the intersection of all list elements). Is there a command in > regular Python to do this? I would

[Tutor] flattening a list

2005-01-11 Thread Bill Kranec
Hello, I have a list of lists, for example [ [1,2] , [3,4] ], and I would like to pass all the elements of that list as arguments to a function (for example the intersection of all list elements). Is there a command in regular Python to do this? I would like to avoid the hassle and speed hit