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 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]]]

--

ngel Gutirrez Rodrguez - XXXX@XXXXX.COM

Instituto de Ciencia de los Materiales de Madrid - CSIC

SpLine - European Syncrothorn Radiation Facility - Grenoble - France

Postal adress: Departamento de Qumica Fsica y Analtica

Universidad de Oviedo - c/Julin Clavera 8 33006 - Oviedo

Asturias - Spain

E-mail: XXXX@XXXXX.COM Telf.: +34-985103687

Hint : what's exactly the difference between deep(x) and [x] ?

for N:

mylist = [mylist]

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 ' XXXX@XXXXX.COM '.split('@')])"

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, 1, 1]]])

James

--

James Stroud

UCLA-DOE Institute for Genomics and Proteomics

Box 951570

Los Angeles, CA 90095

http://www.yqcomputer.com/

numpy is the successor to numarray, so if you are just starting with arrays,

please get started with numpy. It should also be noted that numpy can create

arrays of objects as well as arrays of numbers.

In [1]: from numpy import *

In [2]: empty((1,2,3), dtype=object)

Out[2]:

array([[[None, None, None],

[None, None, None]]], dtype=object)

http://www.yqcomputer.com/

--

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma

that is made terrible by our own mad attempt to interpret it as though it had

an underlying truth."

-- Umberto Eco

Right that!

No need to. Former solution worked fine. Thanks!

--

ngel Gutirrez Rodrguez - XXXX@XXXXX.COM

Instituto de Ciencia de los Materiales de Madrid - CSIC

SpLine - European Syncrothorn Radiation Facility - Grenoble - France

Postal adress: Departamento de Qumica Fsica y Analtica

Universidad de Oviedo - c/Julin Clavera 8 33006 - Oviedo

Asturias - Spain

E-mail: XXXX@XXXXX.COM Telf.: +34-985103687

Thanks! That's anotehr solution, yes!

--

ngel Gutirrez Rodrguez - XXXX@XXXXX.COM

Instituto de Ciencia de los Materiales de Madrid - CSIC

SpLine - European Syncrothorn Radiation Facility - Grenoble - France

Postal adress: Departamento de Qumica Fsica y Analtica

Universidad de Oviedo - c/Julin Clavera 8 33006 - Oviedo

Asturias - Spain

E-mail: XXXX@XXXXX.COM Telf.: +34-985103687

1. Sort a List, in a List of Lists of Lists

2. Compare List A to List B, Return List B Items Not in List A

3. list/sequence problem: a 'keep' list to a list of 'kept' lists

4. validation list--list depends on the selection of first list

5. Grey listing, white listing, black listing

6. Extracting a List from a List of lists

7. consing a list-of-numbers to a list-of-lists-of-numbers

8. list of ascii to list of chars, and list question

9. [newbie] getting the longest list from a list of lists

10. list/sequence problem: a 'keep' list to a list of

11. Is there an easy way to replace list A instances with list B instances (sorted lists).

12. Data Validation Lists - Generating a list based on another list's result

13. Howto: extract a 'column' from a list of lists into a new list?

14. create new list from list A, but with exclusions from a list B

15. Lists within Lists or Nested Linked Lists...

6 post • Page:**1** of **1**