这是长代码的一部分。如何将选择排序的交换更改为全局函数?
def SortByGenre(G):
for i in range (len(G)-1):
minimum = i
mingenre = G[minimum][2]
price = G[minimum][3]
artist = G[minimum][1]
title = G[minimum][0]
for j in range (i+1, len(G)):
if mingenre > G[j][2]:
mingenre = G[j][2]
price = G[j][3]
artist = G[j][1]
title = G[j][0]
minimum = j
tempgenre = G[i][2]
tempprice = G[i][3]
tempartist = G[i][1]
temptitle = G[i][0]
G[i][2] = mingenre
G[i][3] = price
G[i][1] = artist
G[i][0] = title
G[minimum][2] = tempgenre
G[minimum][3] = tempprice
G[minimum][1] = tempartist
G[minimum][0] = temptitle
return G
我想把这个部分变成一个全局函数,我可以用于我程序的其他部分:
tempgenre = G[i][2]
tempprice = G[i][3]
tempartist = G[i][1]
temptitle = G[i][0]
G[i][2] = mingenre
G[i][3] = price
G[i][1] = artist
G[i][0] = title
G[minimum][2] = tempgenre
G[minimum][3] = tempprice
G[minimum][1] = tempartist
G[minimum][0] = temptitle