I’m getting to know Julia and found some quick little exercises at exercism.io (http://exercism.io/languages/julia/exercises). In the Nucleotide Count exercise, based on the runtests.jl file, the preferred Dict structure is:
Dict(‘A’ => 0, ‘C’ => 0, ‘G’ => 0, ‘T’ => 0)
Is this preferred to String based keys? i.e. Dict(“A”=>0).
My first solution did this for String keys (trimmed slightly).
count is the Dict,
myStr the input string.
for i in myStr
count["$i"] += 1
This failed the test because of the data type of the key. So I changed to using indexes on the input string, which worked as well, but felt less elegant somehow. I realize it’s quite subjective.
for i in 1:length(myStr)
count[myStr[i]] += 1
Is there a reason to choose one over the other, aside from passing the supplied runtest.jl? Style, idiom, performance?