Is it possible to deselect vertices in Python? I have an existing selection which I'd like to further isolate using Python scripting. In this instance the math is simply that if the X coordinate is greater than zero, it should be deselected.

I already have this code, which successfully selects half of the object:

import bpy

obj = bpy.context.active_object
bpy.ops.object.mode_set(mode = 'EDIT') 
bpy.ops.mesh.select_mode(type="VERT")
bpy.ops.object.mode_set(mode = 'OBJECT')

for i in range(len(obj.data.vertices)):
    if obj.data.vertices[i].co.x &gt; 0:
        obj.data.vertices[i].select = True

bpy.ops.object.mode_set(mode = 'EDIT')


If I change the &gt; to a &lt; and run the script, then it selects the rest of the object, so it does seem that selections are able to build upon each other.

If I change True to False,  I would expect selected areas matching the logic (co.x &gt; 0) to be deselected, since it is setting the select property to false. However, this doesn't actually work. Running the script with False instead of True results in the selection being unchanged regardless of any conditions I set. It seems that nothing happens when I use .select = False. There are no errors printed to the console or anything.

After finding this question, it seems that I'm not the only one with the problem, but the answers simply seem to indicate that this is impossible due to the way Blender works with selecting faces and edges. So, is it possible? Can we deselect all connected faces and edges of a vertex in a Python script so that we can deselect the vertex?
if you want to run it in object mode: 

import bpy
vert = bpy.context.object.data.vertices
face = bpy.context.object.data.polygons #not faces!
edge = bpy.context.object.data.edges
#vertices can be selected 
#to deselect vertices you need to deselect faces(polygons) and edges at first
for i in face:                   
    i.select=False               
for i in edge:
    i.select=False
for i in vert:
    i.select=False
    if i.co.x &gt; 0:
        i.select = True