How do you rename vertex group

I am wanting to make a plugin that can remove support loops off of a high poly model to speed up the workflow
but I can not find out how to set vertex group name I have already looked online and could not find anything that works

here are some things i found , not sure if it is the right way to rename them

assuming your object is the default cube and you have two vertex groups named group1 and group2 :

to rename group1
bpy.data.objects[‘Cube’].vertex_groups[‘group1’].name = ‘new group name’
to get the names of all vertex groups
bpy.data.objects[‘Cube’].vertex_groups.keys()

you can also use their indices to access them , for example this returns the number of vertex groups , in this case 2
len(bpy.data.objects[‘Cube’].vertex_groups)
you can access them with their indices :
bpy.data.objects[‘Cube’].vertex_groups[0].name = ‘new vgroup name 1’
bpy.data.objects[‘Cube’].vertex_groups[1].name = ‘new vgroup name 2’