How to get indices of the faces to which a material has been applied, using Python?
This script iterates over the polys and adds their indices to the appropriate key (material name) if the material is applied to each of the current faces:

import bpy

o = bpy.context.object # Active object

# Initialize dictionary of all materials applied to object with empty lists 
# which will contain indices of faces on which these materials are applied
materialPolys = { ms.material.name : [] for ms in o.material_slots }

for i, p in enumerate( o.data.polygons ):
    materialPolys[ o.material_slots[ p.material_index ].name ].append( i )

print( materialPolys )


For this object, an icosphere which has 4 materials (3 of which are actually applied to faces), this is the result:



{
    'Material.002': [7, 12, 41, 42, 53, 54, 55], 
    'Material.004': [], 
    'Material.003': [10, 19, 34, 35, 47, 48, 49, 62], 
    'Material.001': [0, 1, 2, 3, 4, 5, 6, 8, 9, 11, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 36, 37, 38, 39, 40, 43, 44, 45, 46, 50, 51, 52, 56, 57, 58, 59, 60, 61, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79]
}