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
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
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
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
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
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
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
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:
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
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,
Á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
Á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
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
13 matches
Mail list logo