# Dict index with multiple keys versus tuple

As I struggle to scale the slopes of julia sagacity I encountered the following and the fact that it didn’t throw an error, well, threw me.

``````julia> Acc_rd
Dict{Tuple{Int64, Int64}, Vector{Int64}} with 12 entries:
(101521, 12124) => [23434]
(101521, 9412)  => []
(100105, 7207)  => [20661, 20662, 20911, 20912, 21111, 21112, 21113, 21114, 21181, 21182  …  26…
(102653, 12124) => [20911, 20912, 22311, 22314, 23431, 24971, 25901, 25902, 26351, 26352]
:
``````

and then

``````julia> Acc_rd[101521, 12124]
1-element Vector{Int64}:
23434
``````

I’ve no doubt that there is some magic happening behind the scenes that “fills in the blanks” but I can’t help having the feeling that at some point features become counter-productive.

As I said at the outset, spare a thought…

`Acc_rd[101521, 12124]` is equivalent to `Acc_rd[(101521, 12124)]`. This was very arguably a bad idea, but it made it into Julia 1.0, so it’s here to stay at least until Julia 2.0.

6 Likes

BTW, if you want to see the magic for yourself, just do:

``````@edit Acc_rd[101521, 12124]
``````

which should point you to:

``````# t[k1,k2,ks...] is syntactic sugar for t[(k1,k2,ks...)].  (Note
# that we need to avoid dispatch loops if setindex!(t,v,k) is not defined.)
getindex(t::AbstractDict, k1, k2, ks...) = getindex(t, tuple(k1,k2,ks...))
``````
1 Like