[英]Convert a list of words to list of numbers that were previously assigned in Python(2.7.1)
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 我有一个代码"aaabbbcccdddeee"
,我将其分成3个字母词(例如'aaa'
, 'bbb'
, 'ccc'
等),并使用
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'
mapping = <your dictionary>
instr = <your data>
result = [mapping[instr[i:i+3] ] for i in range(0, len(instr), 3) ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.