I would like to convert the following JAVA code to python (am a beginner in Python)
public void selectionSort(int[] arr) {
int i, j, minIndex, tmp;
int n = arr.length;
for (i = 0; i < n - 1; i++) {
minIndex = i;
for (j = i + 1; j < n; j++)
if (arr[j] < arr[minIndex])
minIndex = j;
if (minIndex != i) {
tmp = arr[i];
arr[i] = arr[minIndex];
arr[minIndex] = tmp;
}
}
}
This is what I wrote but it doesn't work and I cannot figure out what am I doing wrongly
A = [86, 2,4 ,5, 6122, 87]
def selectionSort(a):
n = len(a)
print ("n = ", n)
for i in range (0, n-1):
minIndex = i
j = i+1
for j in range (0, n):
if(a[j] < a[minIndex]):
minIndex = j
if minIndex != i:
tmp = a[i]
a[i] = a[minIndex]
a[minIndex] = tmp
selectionSort(A)
print(A)
Please help me understand why