0
listaSupermercados1 = [[1, 10], [2, 20], [1, 15]]
def comprarBananas(listaSupermercados):
listaSupermercados.append(listaSupermercados)
comprimentoLista = len(listaSupermercados) -1
posicao = 0
posica1 = 1
posicaoSubsequente = posica1 + 1
listaOrganizada = []
while posicao < (comprimentoLista):
valorUnitarioPosicaoInicial = listaSupermercados[posicao][posica1]
valorUnitarioPosicaoSubsequente = listaSupermercados1[posicaoSubsequente][posica1]
if valorUnitarioPosicaoInicial < valorUnitarioPosicaoSubsequente:
listaOrganizada.append(listaSupermercados[posicao])
else:
listaOrganizada.append(listaSupermercados[posicaoSubsequente])
posicao += 1
posicaoSubsequente = + 1
print(listaOrganizada)
comprarBananas(listaSupermercados1)
Each sub-list has 2 positions with integers and I want to create a new list in ascending order by the value of each element in the 2nd position of the sub-lists But I get the mistake:
ERROR: if valueUnitesPositionInitial < valueUnitesSubscribing: Typeerror: '<' not supported between instances of 'list' and 'int'
BAH doesn’t even post right I can :-(
– Rafael Muinarczyki
Your code is not showing error, but it is not doing what it should. In a pythonic way, you could do something like:
sorted(listaSupermercados1, key=lambda x: x[1], reverse=True)
– Paulo Marques
Hi Paulo Thanks! I couldn’t understand your code (I’m new in Python) I could explain how I put it in my code?
– Rafael Muinarczyki
Got it ! Thank you very much
– Rafael Muinarczyki
listSupermercados1 = [[1, 10], [2, 20], [1, 15]] def buyBananas(listSupermercados): listOrganizada = Sorted(listSupermercados, key=lambda x: x[1]) print(listOrganized) &#x;buyBananas(listSupermercados1)
– Rafael Muinarczyki