Change material & Remove double

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 *


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

mat.append( Blender.Material.Get(mat_name) )		

#print mat[0].name
print "---%s"%(   # this should be empty
print "---%s"%(mes.materials[0].name)

#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.