# Python: Duplicating a group with animation

I have a group. The first object is a mesh and the second is an armature with multiple actions that controls the mesh. How can I duplicate this group with python in a for x in range(number) statement and be able to set the action on each armature that is created. This way, each duplicate group will have it's own animation.

Make a copy of all objects in group "Group" and assign to a number of new groups, "NewGroup[.nnn]" If the object in the new group has a parent or an armature modifier object in "Group" then it is assigned to the respective copy in the new group.

import bpy
scene = bpy.context.scene
number = 5 # make 5 group copies
group = bpy.data.groups.get("Group")
obs = [o for o in group.objects]
if group is not None:
for g in range(number):
group_objects = [o.copy() for o in bpy.data.groups['Group'].objects]
new_group = bpy.data.groups.new("NewGroup")
for o in group_objects:
# parent
if o.parent in obs:
o.parent = group_objects[obs.index(o.parent)]
# armature modifiers
armature_mods = [m for m in o.modifiers if m.type == 'ARMATURE']
for m in armature_mods:
if m.object in obs:
m.object = group_objects[obs.index(m.object)]

    for o in group_objects: