i just realised your sorting funtion is not correct.
5 1 1
6 5 4 3 2
[[5, 4, 3, 2, 6], [1, 2, 3, 4, 0]]
indx=[i for i in range(len(arr))]
for i in range(len(arr)):
m = min(arr[i:])
if arr[i] != m:
x = i + arr[i:].index(m)
arr[i],arr[x],indx[i],indx[x] = arr[x],arr[i],indx[x],indx[i]
here is a code that sorts well.
but this is obviously going to be very heavy to sort …
and i’d prefer using inbuilt sort function that we have.
to keep index updated with sorted list you can creat a class of 2 values (value of x and index of x), and define a lt function for that class so you can sort array of objects of this class. here is how it will look.
self.x = x
self.i = i
def __lt__(self,other): <- this function define less than operation between objects of point class that we just created
return self.x < other.x
A = [point(int(j),i+1) for i,j in enumerate(input().split())]
^ input of values of A
A.sort() <- A is sorted
Here to Acces value of point you can use A.x
and for index A.i