0

I have 2 lists:

a = [orange,apple,peach,watermelon,gum]

b = [3,4,1,2,0]

In this case, I want to take the values stored in each index in list b and then move the elements that correspond to each element in list a in accordance to that value.

To give a clearer example, with the above code if re-ordered the result would be:

a = [gum,peach,watermelon,orange,apple]

Since the first item in list b is 3 I need to move the corresponding first value in list a (in this case oranges) to that index position of the list, so it has now moved to index position 3 after being re-ordered.

Since 0 is the last element of list b it corresponds to the last element in list a (in this case gum), so the last element of list a should be moved to index position 0, as above.

We can assume that list b will be the same length as list a and that the index values will correspond to the ones in list a.

Community
  • 1
  • 1
Boyan Anakiev
  • 101
  • 1
  • 1
  • 3

0 Answers0