I am trying to code in python this simple task (part of a bigger project):
I have two lists where the first one, let's say A = [1, 2, 3, 4, 5, 6] is sorted and the second one, let's say B = [3, 4, 1, 6, 2, 5] is not sorted. What I want to achieve is to obtain the value of the index for each element of the sorted list A in list B. For example, I want to come with the result of index i = 3 when I search for the element A[5] = 6. I have implemented in the simple way as follows:
for i in range(6):
for j in range(6):
if A[i] == B[j]:
index = j
I would want to come up with a way which reduces it to only one loop instead of these two nested for loops.