samedi 26 octobre 2019

Why do I get error when trying to remove from list?

My list looks something like this:

list = [(0.0, 0.0), (30.0, 0.0), (60.0, 0.0), (90.0, 0.0), (120.0, 0.0), (150.0, 0.0), (180.0, 0.0)]

I want to remove all the elements from the list that I have whithin another list.

objects_to_remove = [](180.0, 0.0), (90.0, 0.0), (30.0, 0.0)]

This is the code that I have to do this

 for x in objects_to_remove:
          list.remove(x)

I got this error

ValueError: list.remove(x): x not in list

So I tried this

for x in objects_to_remove:
          list.pop(list.index(x))

But then I got this error

ValueError: (30.0, 0.0) is not in list

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire