# how to check if a vertex group is empty or not with python

I am figuring out a way to check if vertex group is empty or not. if it contains at least 1 vertex or totally empty.

I am trying to make if condition to check for empty vertex group and delete the vertex group if it's empty

can I do this with vertex group data or should i use functions from bmesh

Using list comprehension

similar to that used in this answer

Because we are only interested in empty group will use python any to move on quickly when a non empty group is found.

import bpy
ob = bpy.context.object
me = ob.data
for vg in ob.vertex_groups:
mtvg = not any(vg.index in [g.group for g in v.groups] for v in me.vertices)
print(vg.name, mtvg)


Then if vertex group vg is empty can remove with

ob.vertex_groups.remove(vg)