473,378 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

List of lists of lists of lists...

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 Gutiérrez Rodr*guez - ag*@fq.uniovi.es
Instituto de Ciencia de los Materiales de Madrid - CSIC
SpLine - European Syncrothorn Radiation Facility - Grenoble - France

Postal adress: Departamento de Qu*mica F*sica y Anal*tica
Universidad de Oviedo - c/Julián Claver*a 8 33006 - Oviedo
Asturias - Spain
E-mail: ag*@fq.uniovi.es Telf.: +34-985103687
May 8 '06 #1
3 1205
Á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 'o****@xiludom.gro'.split('@')])"
May 10 '06 #2
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 - ag*@fq.uniovi.es
Instituto de Ciencia de los Materiales de Madrid - CSIC
SpLine - European Syncrothorn Radiation Facility - Grenoble - France

Postal adress: Departamento de Qu*mica F*sica y Anal*tica
Universidad de Oviedo - c/Julián Claver*a 8 33006 - Oviedo
Asturias - Spain
E-mail: ag*@fq.uniovi.es Telf.: +34-985103687
May 15 '06 #3
Robert Kern wrote:
James Stroud wrote:
http://numeric.scipy.org

Thanks! That's anotehr solution, yes!
--
Ángel Gutiérrez Rodr*guez - ag*@fq.uniovi.es
Instituto de Ciencia de los Materiales de Madrid - CSIC
SpLine - European Syncrothorn Radiation Facility - Grenoble - France

Postal adress: Departamento de Qu*mica F*sica y Anal*tica
Universidad de Oviedo - c/Julián Claver*a 8 33006 - Oviedo
Asturias - Spain
E-mail: ag*@fq.uniovi.es Telf.: +34-985103687
May 15 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Philippe C. Martin | last post by:
Hi, I'm looking for an easy algorithm - maybe Python can help: I start with X lists which intial sort is based on list #1. I want to reverse sort list #1 and have all other lists sorted...
1
by: Glen Able | last post by:
Hi, I have a collection of lists, something like this: std::list<Obj*> lists; Now I add an Obj to one of the lists: Obj* gary; lists.push_front(gary);
1
by: Booser | last post by:
// Merge sort using circular linked list // By Jason Hall <booser108@yahoo.com> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> //#define debug
11
by: Neo | last post by:
Hi Frns, Could U plz. suggest me how can i reverse a link list (without recursion)??? here is my code (incomplete): #include<stdio.h>
4
by: MJ | last post by:
Hi I have written a prog for reversing a linked list I have used globle pointer Can any one tell me how I can modify this prog so that I dont have to use extra pointer Head1. When I reverse a LL...
2
by: Cox | last post by:
Hello: My address jsmith435@cox.net is subscribed to at least the PHP General mailing list. I have for days now been trying to unsubscribe from all PHP mail lists. I have followed the...
16
by: Michael M. | last post by:
How to find the longst element list of lists? I think, there should be an easier way then this: s1 = s2 = s3 = if len(s1) >= len(s2) and len(s1) >= len(s3): sx1=s1 ## s1 ist lngster
19
by: Dongsheng Ruan | last post by:
with a cell class like this: #!/usr/bin/python import sys class Cell: def __init__( self, data, next=None ): self.data = data
10
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
36
by: pereges | last post by:
Hi, I am wondering which of the two data structures (link list or array) would be better in my situation. I have to create a list of rays for my ray tracing program. the data structure of ray...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.