Remove a value from a list

Asked

Viewed 103 times

0

I want to remove two values from a list. Of type I have an array:

vet[0]*3

for i in range(3):
    vet[i]=input('Digite um valor: ')

I want to remove as much and as little as possible. How do I?

I’ve tried to do vet.remove(max(vet)), but it can’t be.

1 answer

1

In python you define a list like this:

vet = []

To add elements in the list via inputs you can do

for i in range(3):
   vet.append(int(input('Digite um valor: ')))

Let’s say the user typed 10, 20, 30, if Oce wanted to see vet content, could do:

print(vet)

And I’d have the way out:

[10, 20, 30]

To exclude items whose values are maximum and minimum:

# Excluindo o valor máximo:
vet.pop(vet.index(max(vet)))

# Excluindo o valor mínimo
vet.pop(vet.index(min(vet)))

# Imprimindo a lista resultante:
print(vet)

Exit:

[20]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.