import copy


def remove_items(data, items, action='r'):
    """Removes identified items from a list and returns updated list.
    
    Only works on lists of items, not on nested lists. If action flag is set to
    'k' then the items in items are kept and all items not in items are
    removed.
    
    Args:
        data (list): List of items to be processed.
        items (list): List of items to be checked against.
        action (str): Action to take on items in items:
            - 'r' Items in items are removed if found.
            - 'k' Items not in items are removed if found.
    
    Returns:
        updated_data (list): Data after processing.
    """
    updated_data = copy.deepcopy(data)
    print('\nProcessing items')
    num_students = len(updated_data) # For calculating % complete
    n = 0
    for item in updated_data:
        # Display progress
        n += 1
        progress = round((n/num_students) * 100)
        print("\rProgress: {}{}".format(progress, '%'), end="", flush=True)
        if item in items:
            if action == 'r': # Remove item
                updated_data.remove(item)
            elif action == 'k': # Keep item
                continue
            else:
                continue
        else: # item not in items
            if action == 'r': # Keep item
                continue
            elif action == 'k': # Remove item
                updated_data.remove(item)
            else:
                continue      
    print('\rFinished processing items')
    return updated_data