Search code examples
pythonlistpywinautocoords

Find and replace a screen coords from a list


I'm using OpenCV to find some images on screen and return it into a list of coords so pywinauto click on them, so everytime an image is found it gives a list like this:

[(297, 323), (390, 323), (297, 370), (437, 393), (314, 349), (408, 349)]

I want to get rid of (297, 323) and (390, 323) for example, how is it possible?

I have been searching for hours but my english ain't perfect so I'm always finding the wrong answers :(


Solution

  • if you want to remove all occurences:

    a = [(297, 323), (390, 323), (297, 370), (437, 393), (314, 349), (408, 349)]
    b = [x for x in a if x != (297, 323) and x!= (390, 323)]
    print(b)
    

    if you just want to remove the first occurence:

    a = [(297, 323), (390, 323), (297, 370), (437, 393), (314, 349), (408, 349)]
    a.remove((297, 323))
    a.remove((390, 323))
    print(a)