My question is how can I interact with this list in order to make comparisons between values.
def trocar(vals, posX, posY):
temp = vals[posX]
vals[posX] = vals[posY]
vals[posY] = temp
return None
def ordenar(valores):
tamanho = len(valores) - 1
troquei = True
while troquei:
troquei = False
for i in range(tamanho):
if valores[i] > valores[i + 1]:
trocar(valores, i, i + 1)
troquei = True
tamanho -= 1
return valores
lista= [('Ana', 30, 6.69), ('João', 25, 6.11), ('Pedro', 30, 6.69), ('Maria', 28, 5.45), ('Thiago', 40, 5.45), ('Raquel', 26, 10.0)]
x=ordenar(lista)
print(x) # [('Ana', 30, 6.69), ('João', 25, 6.11), ('Maria', 28, 5.45), ('Pedro', 30, 6.69), ('Raquel', 26, 10.0), ('Thiago', 40, 5.45)]
My intention is to print the names in order according to the values:
In the code above only one of the objectives has been achieved; get the names in alphabetical order