Delete all materials that aren't assigned to a face?
For future landers. This works on selected objects and its using new APIs so 2.80+ only.
import bpy

objs = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']
for obj in objs:
        bpy.context.view_layer.objects.active = obj
        bpy.ops.object.material_slot_remove_unused()