def apply_action_to_form_data(action, form_data):
    new_form_data = form_data
    (action_id_prefix, action_index, action_type) = action[len('action_'):].rsplit('__', 2)
    if (action_type == 'delete'):
        deleted_item_index = int(action_index)
        parent_id_prefix = action_id_prefix
        new_form_data = {}
        for name in form_data:
            if (not name.startswith((parent_id_prefix + '__'))):
                new_form_data[name] = form_data[name]
            else:
                (item_index, id_suffix) = name[(len(parent_id_prefix) + 2):].split('__', 1)
                item_index = int(item_index)
                if (item_index < deleted_item_index):
                    new_form_data[name] = form_data[name]
                if (item_index > deleted_item_index):
                    new_name = ((((parent_id_prefix + '__') + str((item_index - 1))) + '__') + id_suffix)
                    new_form_data[new_name] = form_data[name]
    return new_form_data
def apply_action_to_form_data(action, form_data):
    new_form_data = form_data
    (action_id_prefix, action_index, action_type) = action[len('action_'):].rsplit('__', 2)
    if (action_type == 'delete'):
        deleted_item_index = int(action_index)
        parent_id_prefix = action_id_prefix
        new_form_data = {}
        for name in form_data:
            if (not name.startswith((parent_id_prefix + '__'))):
                new_form_data[name] = form_data[name]
            else:
                (item_index, id_suffix) = name[(len(parent_id_prefix) + 2):].split('__', 1)
                item_index = int(item_index)
                if (item_index < deleted_item_index):
                    new_form_data[name] = form_data[name]
                if (item_index > deleted_item_index):
                    new_name = ((((parent_id_prefix + '__') + str((item_index - 1))) + '__') + id_suffix)
                    new_form_data[new_name] = form_data[name]
    return new_form_data