Im trying to write a procedure to sort the tuples in a list based on their product value per tuple. I just tried sorting them first using a while loop but Im not able to integrate the multiplication of the numbers inside the tuple. The code I have so far is:
def sort_list (a):
i = 0
while i < len(a):
key = i
j = i + 1
#first checking throuh the whole list if any number is bigger
while j < len(a):
if a[key] > a [j]:
key = j
j += 1
#swap the numbers if the key one (i) is bigger than the j one the j one will be the new key
# and swapped in the next section!
a[i], a[key] = a[key], a[i]
i += 1
return a
m = [(2, 3.0), (3, 1.0), (4, 2.5), (1, 1.0)]
sort_list(m)
print (m)
# should output : [(1, 1.0), (3, 1.0), (2, 3.0), (4, 2.5)]