Problem is here Countries[j+1][2] = Countries[j][2]
you have to replace with Countries[j+1] = Countries[j]
Also
you have to invoke this
if not madeSwap:
return
In outer for
And return list
def bubblesort():
Countries = [["Afghanistan",647500.0,3],["Albania",28748.0,1],["Zimbabwe",390580.0,2]]
for i in range(0,len(Countries)):
madeSwap = False
for j in range (0,len(Countries)-(i+1)):
if Countries[j][2] > Countries[j+1][2]:
temp = Countries[j+1]
Countries[j+1] = Countries[j]
Countries[j] = temp
madeSwap = True
if not madeSwap:
return Countries
return Countries
>>> bubblesort()
[['Afghanistan', 647500.0, 1], ['Zimbabwe', 390580.0, 2], ['Albania', 28748.0, 3]]