Reputation: 30717
I have a code "aaabbbcccdddeee"
that I split up into 3 letter words (such as 'aaa'
,'bbb'
,'ccc'
. . . and so on) and assigned a number value to them using
d=dict(zip(('aaa','bbb','ccc','ddd','eee'),('123','234','345','456','567')))
If random sequence that has
random='aaabbbdddccceeedddbbbaaaeeeccc'
How can I create a list that converts the random sequence into a list composed of the number values that were assigned previously
Example:
random='aaabbbdddccceeedddbbbaaaeeeccc'
to produce
'123','234','456','345','567','456','234','123','567','345'
Upvotes: 0
Views: 384
Reputation: 110476
mapping = <your dictionary>
instr = <your data>
result = [mapping[instr[i:i+3] ] for i in range(0, len(instr), 3) ]
Upvotes: 3