# Python: Assign selected faces to vertex group

I have a script that selects some random faces and splits them. I would like to add the selection to a vertex group. I can't get my script to assign the selection to a vertex group. Thank you for the help.

            sub2 = 0
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.select_random(percent=55, seed=10, action='DESELECT')
bpy.ops.mesh.split()
group = context.object.vertex_groups.new()
group.name = ("Island" + str(sub2))
bpy.ops.object.vertex_group_assign()


You as missing "bpy" in the line 4, so it should be:

group = bpy.context.object.vertex_groups.new()


Don't forget to import bpy:

import bpy


## Whole script:

import bpy
sub2 = 0
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.select_random(percent=55, seed=10, action='DESELECT')
bpy.ops.mesh.split()
group = bpy.context.object.vertex_groups.new()
group.name = ("Island" + str(sub2))