Why do I get a key error when using a created symbol?

I thought it would be handy to create Symbols, and that worked, but why do I get a key error when I try to use them in a Dict?

fim = [Symbol(n) for n in "abcdef"]

6-element Vector{Symbol}:
 :a
 :b
 :c
 :d
 :e
 :f

d = Dict()
for sym in fim
    d[sym]=>14
end

KeyError: key :a not found

Don’t you want just

d[sym] = 14

(instead of =>?) With => you are trying to create a pair that binds d[sym] to 14, but d[sym] is not defined.

6 Likes