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
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
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
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
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
> > 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.
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[
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
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
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
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
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
12 matches
Mail list logo