Array in array
bearophile
bearophileHUGS at lycos.com
Sat Oct 27 18:00:18 PDT 2012
xfiles:
> I want create a multi array like python.
> For example(in python):
> a=[1,2]
> a.append([1234],3)
> a.append([[4],5],6)
>
> and result is = [1,2,[1234],3,[[4],5],6]
>
> How can I do this in D
In D there are several different ways to represent that data
structure, but being D not dynamically typed (and not having
algebraic data types) none of them are as nice as solutions in
Python (or ML-derived languages).
This shows one way to do it in an efficient way:
http://rosettacode.org/wiki/Flatten_a_list#D
If efficiency is less important, you can use an heap-allocated
multi-way tree. Or even a little hierarchy with two classes.
Another solution is to use some kind of variant/any/multi data
type.
So explain your needs better and maybe someone will suggest what
specif solution to use.
Bye,
bearophile
More information about the Digitalmars-d
mailing list