I have a list of numbers:
a = [4,4,4,4,4,4,4,4,4,........................,4,3,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4]
I want to transform the values according to a custom dictionary, for example:
cust_dict ={4:'four',1:'one',2:'two',3:'three'}
To get the following:
a= [four,four,four,four,four.....,four, three,two,....]
The only code I have done is with a for loop:
for i in range(len(a)):
a[i] = cust_dict[a[i]]
Is there a more efficient way (in pure python), thus avoiding for-loop ? For a list of 35k items I took around 4ms with this code.