ordered_elements = ['A','B','C', 'D', 'E', 'F']
index= [308,302,303,405,506,609]
element_index_mapping = {letter:idx for e, letter in zip(ordered_elements, index)}
out = []
for letters in elements:
indices_for_letters = []
for letter in letters:
indices_for_letters.append(element_index_mapping.get(letter))
out.append(indices_for_letters)
elements = [['A', 'B'], ['B', 'C'], ['D', 'E', 'F']]
ordered_elements = ['A', 'B', 'C', 'D', 'E', 'F']
index = [308, 302, 303, 405, 506, 609]
out = [[index[ordered_elements.index(c)] for c in sl] for sl in elements]
print(out)
4条答案
按热度按时间mbzjlibv1#
您可以使用Map字典:
输出:
im9ewurl2#
nle07wnf3#
我不推荐这样做,但如果你想剪短,也许你可以试试这个:
mnemlml84#
虽然此处没有安全检查,但您可以按以下方式操作: