Change all elements in a list of indices corresponding to another list

Rosa :

I have 2 lists:

b = ['zero', 'one', 'two']
c = [0, 0, 0, 1, 1, 2, 1, 0, 2, 0]

Is there an elegant way to change every element in c and get

c = ['zero', 'zero', 'zero', 'one', 'one', 'two', 'one', 'zero', 'two', 'zero'] 
Prakhar Londhe :

I think just

c = [b[i] for i in c]

would do the trick

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=9549&siteId=1