Have you ever wanted to send a list of times to one of Maya’s keyframe commands (keyframe, setKeyframe, copyKey, cutKey, keyTangent, etc.) only do discover that it accepts a time range instead? Don’t worry. There is a way to do what you want!
The trick is to send a list of single-frame time ranges. For example:
keysToCut = [5, 20, 25, 47, 48]
timeRange = [(key,) for key in keysToCut]
cmds.cutKey('pCube1.translateX', time=timeRange, clear=True)
This also works for the “index” and “float” flags.
Why this works:
The clue is in the documentation for each command flag. For example, look up the “cutKey” command, and scroll down to the section about the “time” flag. On the right-hand side of the page are a “C” and an “M”. The “M” is what is important. It means that the flag can be passed multiple values. So if the flag accepts a float, you can pass it a list of floats. If the flag accepts a tuple, you can pass it a list of tuples. In this case, a single-frame time range can be specified as a single-item tuple, like (keyTime,), so we pass a list of those.