這可能是一個基本問題,但我甚至不知道如何正確表達它。從索引列表和字符串列表中創建第三個列表
我有兩個列表:
>>> indexes
array([0, 2, 3, ..., 8, 5, 7]) # choices are between 0 and 8
>>> colors
['red', 'green', 'blue', 'orange', 'black', 'purple', 'yellow', 'grey', 'magenta']
我想做的事情比這個更簡潔和更Python的東西:
color_labels = []
for i in range(len(indexes)):
color_labels.append(colors[indexes[i]])
謝謝!我在找什麼。 –