<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def update_resourcedata(scenario_id, resource_scenarios,**kwargs):
 """ Update the data associated with a scenario. Data missing from the resource scenario will not be removed from the scenario. Use the remove_resourcedata for this task. If the resource scenario does not exist, it will be created. If the value of the resource scenario is specified as being None, the resource scenario will be deleted. If the value of the resource scenario does not exist, it will be created. If the both the resource scenario and value already exist, the resource scenario will be updated with the ID of the dataset. If the dataset being set is being changed, already exists, and is only used by a single resource scenario, then the dataset itself is updated, rather than a new one being created. """

    user_id = kwargs.get('user_id')
    res = None

    _check_can_edit_scenario(scenario_id, kwargs['user_id'])

    scen_i = _get_scenario(scenario_id, user_id)

    res = []
    for rs in resource_scenarios:
        if rs.dataset is not None:
            updated_rs = _update_resourcescenario(scen_i, rs, user_id=user_id, source=kwargs.get('app_name'))
            res.append(updated_rs)
        else:
            _delete_resourcescenario(scenario_id, rs.resource_attr_id)

    db.DBSession.flush()

    return res