vector operation

Asked

Viewed 45 times

0

I have two variables M1 and m2 that change each data set that imports and a vector (measured) with the values, need to see if the values of the vector are greater than M1 or smaller than the M2 and delete them if they are. And list them to see which values were excluded.bold text

1 answer

0

the . split() it "breaks" the string typed by space that is the default, with that the user type 1 2 and M1 receives the 1 and m2 receives the 2, but they are strings, then use the . map() to convert these entries to int and . remove() takes a value and removes it from the list if the condition is met. If you still don’t understand, search in Lists in python.

lista = [10,20,30]
excluidos = []
m1, m2 = map(int, input().split()) # convertendo os valores digitados para int
for n in lista:
    if n > m1 or n < m2:
            excluidos.append(n)
            lista.remove(n)
print(excluidos)

Browser other questions tagged

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