declare -A mydict( [lookma]=initalization )
mydict[foo]=bar
echo "${mydict[foo]}"
list=()
list+=(foo bar baz)
echo "${list[0]}" declare -A outer=(
[inner]="_inner"
)
declare -A _inner=(
[key]="value"
)
Access inner elements via a nameref. declare -n inner="${outer[inner]}"
echo "${inner[key]}"
# value
Currently writing a compiler in Bash built largely on this premise.Try in Python to make a nested defaultdict you can access like the following.
d = <something>
d["a"]["b"]["c"] # --> 42
Can't be done because it's impossible for user code to detect what the last __getitem__ call is and return the default.Edit: Dang it, I mean arbitrary depth.
c = defaultdict(lambda: 42)
b = defaultdict(lambda: c)
a = defaultdict(lambda: b)
a["a"]["b"]["c"] # --> 42Also d["a"] and d["a"]["b"] aren't 42.
Otherwise I'm not sure of a mainstream language that would let you do a.get(x).get(y) == 42 but a.get(x).get(y).get(z) == 42, unless you resorted to monkey patching the number type, as it implies 42.get(z) == 42, which seems.. silly