List of lists of lists of lists...

bruno at modulix onurb at xiludom.gro
Tue May 9 14:16:47 CEST 2006


Á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 way to do it?

for N:
  mylist = [mylist]


> The maine idea is: from a list having the numbre of steps along N
> dimensions, generate a list with an item at each possible point.
> 
> Example 1: N=2  list=[2,3]  result=[[1,2],[1,2],[1,2]]
> Example 2: N=3  list=[3,1,2]  result=[[[1,2,3]],[[1,2,3]]]

I'm afraid I don't understand. Could you forgive my stupidity and
re-explain this a bit more clearly ?

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list