From: stephan at pcrm.win.tue.nl (Stephan Houben)
Date: 26 Apr 1999 10:07:35 +0200
Subject: Bug or Feature?
References: <37208E69.4B022E0C@mediaone.net> <7fr3eg$bqr@world1.bellatlantic.net>
Message-ID: <m3ogkbx0s8.fsf@pcrm.win.tue.nl>
X-UID: 125                                                  

"David Cuthbert" <dacut at kanga.org> writes:

> Fuming Wang <fmwang at mediaone.net> wrote:
>
> Most definitely a feature.  You're getting the same reference for all four
> list elements.  To break it apart:

Nevertheless, it makes it difficult to construct multi-dimensional "arrays".

For this, I would like to propose the following function which I use:
(why isn't something like this in the standard library, or didn't I
just look well enough?)

# Make a tensor (i.e. list of list of lists...)

def make_tensor(*args):
    if args:
	head = args[0]
	tail = args[1:]
	result = []
	for i in range(head):
	    result.append(apply(make_tensor, tail))
	return result
    else:
	return None

if __name__ == '__main__':
    print make_tensor()
    print make_tensor(3)
    print make_tensor(1,2)
    
    
Greetings,

Stephan




