Delete key frames from python scrip

How can I delete the keyframes using Python code?

import bpy'''

This script runs three checks to see if keyframe should be removed.

First it checks if the name of the action is the same as actionName. If actionName is left blank, then it itterates thru 
all actions in the file.

Second, for the actions(s) affected, it checks if the fcurves data path contains the string ifDataPathContainsThis. If it 
has been left blank then this check will automaticly suceed.

Lasts, each keyframe in an affected fcurve will be checked to see if its x cooardint (its frame number) is contained in 
keyFramePositionSet. Each keyframe that passes this check will be added to a list called keyframesToRemove.

Finaly, if keyframesToRemove is not empty, the script will itterate throuh it and remove each point from the fcurves.

actionName = ""

ifDataPathContainsThis = ""

keyFramePositionSet = {0}#to remove keyframes at time 5, 12, and 20, replace the {0} with {5, 12, 20}

def removeKeyframes(action):
    for f in action.fcurves:
        if ifDataPathContainsThis == "" or ifDataPathContainsThis in ifDataPathContainsThis:
            keyframesToRemove = [r for r in f.keyframe_points if[0] in keyFramePositionSet]
            for k in keyframesToRemove:
if actionName != "":
    act =
    if act is not None:
    for a in