I want to order myList
based on the another list(myorderList
) which stores the order of it. For example, myorderList=[3,1,2] indicates that the first element of myList
is mapped to "two" because the smallest number is 1 in myorderList
and then "one" and final element mapped to "zero" according to order of myorderList
.
I have done this it works but i feel that it is not a good method to map the order of myList
. I am looking for a better way to do that.
myorderList=[]
myneworderedList=[]
myList=["zero","two","one"]
myorderList=[3,1,2]
for i in range(len(myList)):# just to eliminate index out of range error
myneworderedList.append(i)
for index,item in enumerate(myorderList):
myneworderedList[int(item)-1]=myList[index]
print myneworderedList
The result:
['two', 'one', 'zero']