Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to remove the value not the index from list

How do I get my code to remove the value instead of removing the index?

availableNumbers= [
1, 2, 3, 4, 5, 6
]

numberOne = int(input("Choose your first number: "))
numberTwo = int(input("Choose your second number: "))

if numberOne in availableNumbers and numberTwo in availableNumbers:
del availableNumbers[numberOne: numberTwo]

print(availableNumbers)

So if 1 and 2 was inputted, 1 and 2 would be removed not 2 and 3

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I believe the function to do so is the remove function. Code:

availableNumbers= [
1, 2, 3, 4, 5, 6
]

numberOne = int(input("Choose your first number: "))
numberTwo = int(input("Choose your second number: "))

if numberOne in availableNumbers and numberTwo in availableNumbers:
    availableNumbers.remove(numberOne)
    availableNumbers.remove(numberTwo)

print(availableNumbers)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading