Set Material to VertexGroup
EDITED:

A slightly more sophisticated version of the previous script, that now finds all the vertex groups of all the vertices of each polygon, isolates the most frequent vertex group and uses it to choose the correct material from the list. Also uses the method to find the material name that matches the vertex group name, as suggested by @batFINGER.

Try this (with the selected object):

import bpy

o = bpy.context.object

for p in o.data.polygons:
    # Get all the vertex groups of all the vertices of this polygon
    verts_vertexGroups = [ g.group for v in p.vertices for g in o.data.vertices[ v ].groups ]

    # Find the most frequent (mode) of all vertex groups
    counts    = [ verts_vertexGroups.count( idx ) for idx in verts_vertexGroups ]
    modeIndex = counts.index( max( counts ) )
    mode      = verts_vertexGroups[ modeIndex ]

    groupName = o.vertex_groups[ mode ].name

    # Now find the material slot with the same VG's name
    ms_index = o.material_slots.find( groupName )

    # Set material to polygon
    if ms_index != -1: # material found
        p.material_index = ms_index