Re: list of lists of lists ....

2006-07-31 Thread yomgui
thanks for all your answers yomgui yomgui wrote: > > Hi, > > I have a list of data (type A) > my list can includes element of type A or a lists, > these list can includes element of type A or a lists, and so on ... > > is there a simple way to obtain a single list of all the elemets > of type

Re: list of lists of lists ....

2006-07-28 Thread bearophileHUGS
You can use this, fast, gives a tuple: from Tkinter import _flatten as flatten --- The xflatten/flatten version I sometimes use, maybe I can put something similar in the cookbook, but it can be improved a lot (and isrecursive is too much fragile): from pprint import isrecurs

Re: list of lists of lists ....

2006-07-28 Thread Michal Kwiatkowski
faulkner wrote: > ok, so, recursion is just functional programming sugar for a loop. And a loop is a procedural programming sugar for tail recursion. 8-) Cheers, mk -- . o . >> http://joker.linuxstuff.pl << . . o It's easier to get forgiveness for being wrong o o o than forgivenes

Re: list of lists of lists ....

2006-07-28 Thread faulkner
doh. ok, so, recursion is just functional programming sugar for a loop. def get_As(L): checking = [elem for elem in L if isinstance(elem, list)]# the equivalent of elem in recursion all_As = [elem for elem in L if isinstance(elem, A)] while checking: new_checking = [] # al

Re: list of lists of lists ....

2006-07-28 Thread faulkner
recursion. def get_As(L): res = [] for elem in L: if isinstance(elem, A): res.append(elem) elif isinstance(elem, list): res += get_As(elem) return res i also have a Tree class in my rc: http://home.comcast.net/~faulkner612/programming/python/pyth

Re: list of lists of lists ....

2006-07-28 Thread yomgui
I forgot the most important, I am looking for a non recursive method. thanks yomgui yomgui wrote: > > Hi, > > I have a list of data (type A) > my list can includes element of type A or a lists, > these list can includes element of type A or a lists, and so on ... > > is there a simple way to

list of lists of lists ....

2006-07-28 Thread yomgui
Hi, I have a list of data (type A) my list can includes element of type A or a lists, these list can includes element of type A or a lists, and so on ... is there a simple way to obtain a single list of all the elemets of type A ? thanks yomgui -- http://mail.python.org/mailman/listinfo/python

Re: List of lists of lists of lists...

2006-05-15 Thread Ángel Gutiérrez Rodríguez
Robert Kern wrote: > James Stroud wrote: > http://numeric.scipy.org > Thanks! That's anotehr solution, yes! -- Ángel Gutiérrez Rodríguez - [EMAIL PROTECTED] Instituto de Ciencia de los Materiales de Madrid - CSIC SpLine - European Syncrothorn Radiation Facility - Grenoble - France Postal adress:

Re: List of lists of lists of lists...

2006-05-15 Thread Ángel Gutiérrez Rodríguez
bruno at modulix wrote: > for N: > mylist = [mylist] > Right that! > I'm afraid I don't understand. Could you forgive my stupidity and > re-explain this a bit more clearly ? > No need to. Former solution worked fine. Thanks! -- Ángel Gutiérrez Rodríguez - [EMAIL PROTECTED] Instituto de Cienc

Re: List of lists of lists of lists...

2006-05-09 Thread Robert Kern
James Stroud wrote: > Numarray does this sort of thing, but you have to familiarize yourself > with its indexing conventions: > > py> import numarray > py> numarray.ones((3,2)) > array([[1, 1], > [1, 1], > [1, 1]]) > py> numarray.ones((1,2,3)) > array([[[1, 1, 1], > [1,

Re: List of lists of lists of lists...

2006-05-09 Thread James Stroud
Ángel Gutiérrez Rodríguez wrote: > I would like to have a list of lists N times deep, and my solution is (in > pseudocode): > > def deep(x): > a=[x] > return a > > mylist=[] > for N: mylist=deep(mylist) > > Is there a more elegant way to do it? > > The maine idea is: from a list having the

Re: List of lists of lists of lists...

2006-05-09 Thread bruno at modulix
Ángel Gutiérrez Rodríguez wrote: > I would like to have a list of lists N times deep, and my solution is (in > pseudocode): > > def deep(x): > a=[x] > return a Hint : what's exactly the difference between deep(x) and [x] ? > mylist=[] > for N: mylist=deep(mylist) > > Is there a more elegant

List of lists of lists of lists...

2006-05-08 Thread Ángel Gutiérrez Rodríguez
I would like to have a list of lists N times deep, and my solution is (in pseudocode): def deep(x): a=[x] return a mylist=[] for N: mylist=deep(mylist) Is there a more elegant way to do it? The maine idea is: from a list having the numbre of steps along N dimensions, generate a list with an