Python Forum

Full Version: comparison in lists
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, i'm a beginner in python and programmation, and i have a doubt about comparison in lists, I have this error

Error:
TypeError: '>' not supported between instances of 'int' and 'list'
but i can try three times after this, so that means it goes into my IF block, right ?
the error is in this line, according to pycharm.
        if lista1[1] > maior:
            maior = lista[1]
the code is written in Portuguese, i hope you can understand.
Thanks

lista = []
lista1 = []
cont = 's'
maior = menor = pessoas = contador = 0

while cont in 'Ss':
    lista1.append(str(input(' NOME : ')))
    lista1.append(int(input(' PESO : ')))
    lista.append(lista1[:])
    pessoas += 1
    contador += 1
    print(lista1[1])  # 38 88 11
    if contador == 1:
        maior = lista1[1]
        menor = lista1[1]
    else:
        if lista1[1] > maior:
            maior = lista[1]
        if lista1[1] < menor:
            menor = lista1[1]
    lista1.clear()

    cont = str(input('Quer continuar ? [S/N]'))

print(f'Foram cadastradas {pessoas} pessoas ')
print(lista)
print(f'o mais pesado pesa {maior} e o mais leve pesa {menor}')
I think you meant line 18
maior = lista[1]
to be
maior = lista1[1]
The error message is self explanatory
Quote:TypeError: '>' not supported between instances of 'int' and 'list'
This happens when maior is zero and lista1[1] is a list (according to this line print(lista1[1]) # 38 88 11). Print both to answer the question yourself.
if lista1[1] > maior:
Thanks guys, i'm very inattentive, i forgot the 1 in 'lista1'