的名单我想号码列表返回字符串列表:我有一个列表返回数的列表,以字符串
copy=[[1,'a'],[55,'b'],[100,'c], [11,d],[66,f]]
,如果我有一个列表code=[1,100,100,11,1,66,1]
结果列表必须像以下列表: ['a','c','c','d','a','f','a']
然后返回一个序列seq=['accdafa']
这意味着,我的每个元素在列表中的副本元素列表中的代码进行比较。 比如我拿件1
从代码我复制列表的元素进行比较 code[0]=1
if code[0]==copy[0][0]:
seq.append(copy[0][1])
else:
go to the next element of the list 'copy'
我尝试代码:
for j in range(len(code)):
if code[j]==copy[0][0]:
seq.append(copy[0][1])
我收到以下错误:
IndexError: list index out of range
对于列表中其余元素的相同内容code
是啊,看看dictinoaries。你会发现它会让你的生活变得更加容易,使用它们很容易 – ZekeDroid