# A question about a replacement of element of set

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.

mRNA={"U","C","A","G"}
Flatten[Table[f[{X,Y,Z}],{X,mRNA},{Y,mRNA},{Z,mRNA}],2]



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

Flatten[Table[f[{X,Y,Z}],{X,mRNA},{Y,mRNA},{Z,mRNA}],2]=Range[64]


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

A[{"U","U","C"}]


2

• Thanks! What a nice method! – 김기훈 Apr 27 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];

• Thank you! You saved my time. – 김기훈 Apr 27 at 1:27