I have a sorting algorithm, that sorts 2-d matrices by sums of elements in column:
def task(x):
while isDone < len(arr[0]) - 1:
isDone = 0
for x in range(len(arr[0])):
try:
if arr[0][x] + arr[1][x] < arr[0][x + 1] + arr[1][x + 1]:
tmp0 = arr[0][x]
tmp1 = arr[1][x]
arr[0][x] = arr[0][x + 1]
arr[1][x] = arr[1][x + 1]
arr[0][x + 1] = tmp0
arr[1][x + 1] = tmp1
else:
isDone += 1
except:
pass
The if condition sorts arrays in descending order. Can i dynamically change operator '<' to '>' by passing argument into function, so condition will change, but code that executes, remains the same?