Script to remove all UVs but last one for selected objects & renaming the last UV for all objects

Hi guys. I’m trying to make an addon to simplify a process of removing UVs from a list, except the last one. Then renaming the remaining UV with the same name for all the objects. I don’t really know how to do this part since I’m really new to the scripting and python part of blender. Can anybody help me?

Here is how it works.

import bpy  

object = bpy.context.active_object
print(dir( # show data
print([:]) # show list of uv layers
for uv in[:-1]: # iterate all except the last
    # to prevent any indexing errors from occuring
    # just remove from the first index (same as stack pop)[0])

If you throw this inside the execute of an operator, you have the addon ready.