Deleting non selected objects

I have such a situation.
In script I have selected object, who have his own name. But at scene I have some object which I have left after I used this
I want leave object who have own name, and delete rest of object who hame name like cube.001, cube.002, cube.00n
How delete this non selected objects ?

Greets and Thank for help :slight_smile:

something like this:

import bpy

objs =

objs_to_remove = []

for obj in objs:

bpy.ops.object.delete({"selected_objects": objs_to_remove})
1 Like

Thank You very much for help :slight_smile: