I want my selection sort to sort the values in a certain column (index 3) however I get this message when I run my code.
The error I receive is:
https://i.sstatic.net/dxG2G.png
def selectionSort(lst2):
size = len(lst2)
for i in range(size):
min_idx = i[3]
for j in range(min_idx + 1, size):
if lst2[j] < lst2[min_idx]:
min_idx = j
lst2[i[3]], lst2[min_idx] = lst2[min_idx], lst2[i[3]]
lst2 = lst
selectionSort(lst2)
print(lst2)
First, it is much better to copy/paste your error text into the question so that it is immediately visible and also searchable for future users of the questions.
To understand the error message "'int' object is not subscriptable:"
i
[3]
is the subscript, which is being applied to i
in i[3]
i
, but i
is just an integer and there are no subelements.