To begin with, I'm a poor English speaker, which means it would be hard to read to natives... I was trying to memorize mRNA codons with mathematica.


A code above is what I wrote and what I want to do is to assign a number. Ex) f[{"U","U","U"}]=1, f[{"U","U","C"}]=2 ,etc/

So I tried a code below


But it causes a Set::Write error. How can I fix this?


Something like

MapIndexed[(f[#1]=#2[[1]])&, Tuples[mRNA, 3]]

On the other hand, an Association may be better to use:

A = AssociationThread[Tuples[mRNA, 3] -> Range[64]]

which you can then use with



  • $\begingroup$ Thanks! What a nice method! $\endgroup$ – 김기훈 Apr 27 '19 at 1:25

Wrap Evaluate around the LHS of the assignment:

Evaluate[Flatten[Table[f[{X, Y, Z}], {X, mRNA}, {Y, mRNA}, {Z, mRNA}], 2]] = Range[64];
  • $\begingroup$ Thank you! You saved my time. $\endgroup$ – 김기훈 Apr 27 '19 at 1:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.