Change material & Remove double

Hi,
I am quit a newby in Blender and also in python scripting. I find the function in blender “Remove double” very usefull and powerfull when I import 3d files in Blender.
My problem is that there is no tool to change/replace material and proceed some operations on a selection of meshes.
I wrote a small script to change the material but it it wont remove the old material from the mesh and I am searching the functrion/object call to access the “remove Double” (WKEY 5) functionnality.
Is it any one that had done such a script? ( I actually work with the Blender 2.36 )

#python script
import Blender
from Blender import *
from Blender.Draw import *
from Blender.BGL import *

mat=[]
mat_name=“Verre”

for O in Blender.Object.GetSelected():
mes = O.getData()
#print “—%s”%(mes.materials[0].name)
mat=[]
if mes is not None:
for mt in mes.materials:
print “—%s”%(mt.name)
del mt

O.setMaterials([])
mat.append( Blender.Material.Get(mat_name) )		
O.setMaterials(mat)

#print mat[0].name
print "---%s"%(mes.name)   # this should be empty
mes.materials.append(Blender.Material.Get(mat_name))
print "---%s"%(mes.materials[0].name)
mes.update

#python script

Thanks in advance

I have several things to say

from suchandsuch import * will make your script run slower
[as will import * from suchandsuch]

there is no remove doubles method [in python], but it can be done in python [it would be slow however]

essentially you’d find duplicate verts [ideally not simply comparing all of their locations, but by using some kind of spatial partioning like an octree, then comparing verts on related nodes], modify the faces to use just one vert in each clump that there are duplicates of, then remove the other verticies from the mesh.