Remove duplicate mat with same name and diff index

got this little script

import bpy

mats =

for obj in bpy.context.selected_objects:

for slt in obj.material_slots:
    part ='.')
    if part[2].isnumeric() and part[0] in mats:
        slt.material = mats.get(part[0])

but does not seem to work
I still have mat with same name but different index

anyone has a working simple addon for the selected object ?

happy bl

I have an object with many duplicate name
so I need to remove the duplicate but also re assign the faces to one material

see image here

happy bl

it looks like there must be a base name with no extension!

and also after script run
the object may end up with same mat name in several slot
so need something to eliminate these multi name !

any help appreciated
happy by

Hi, maybe this gives an idea:

will test that

one thing I don’t understand
after doing the other script
the object still has several material with same name
and different verts

how come there are several material slot with same name
but different verts assigned ?

I thought material list was a unique list
looks to me it is not or is it a bug ?