<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def delete_resourcegroupitems(scenario_id, item_ids, **kwargs):
 """ Delete specified items in a group, in a scenario. """

    user_id = int(kwargs.get('user_id'))
    #check the scenario exists
    _get_scenario(scenario_id, user_id)
    for item_id in item_ids:
        rgi = db.DBSession.query(ResourceGroupItem).\
                filter(ResourceGroupItem.id==item_id).one()
        db.DBSession.delete(rgi)

    db.DBSession.flush()