How to select all keyframes between two markers with Python I'm very new to Blender scripting, and coding in general, so any help would be appreciated.

Basically I'm trying to create a small addon to help me create smaller actions out of my larger ones by duplicating them and deleting the parts I don't need. I've been able to create a small script to set up markers where I want, but I can't seem to figure out how to select all of the keyframes within those two markers, invert that selection (ctrl + i), then and delete them.
I would iterate through all the keyframes and check which frame they're on. That's the first number in the x.co vector. Then check that against start/end variables which you would get from markers (didn't include this code). If the frame is between start/end deselect, if outside of that then select it.

import bpy

obj = bpy.context.object             #active object
action = obj.animation_data.action   #current action

start = 20 #first marker variable
end = 80 #second marker variable

for i in action.fcurves:
    for x in i.keyframe_points:
        if x.co[0] &gt; start and x.co[0] &lt; end: #check greater than/less than marker frames
            x.select_control_point=False #deselect if in between markers
        else:
            x.select_control_point=True #select if outside of markers