Bug or Feature?
Stephan Houben
stephan at pcrm.win.tue.nl
Mon Apr 26 04:07:35 EDT 1999
"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
More information about the Python-list
mailing list