def pop(obj, key=0, *args, **kwargs):
    """Pop an element from a mutable collection.

    Parameters
    ----------
    obj : dict or list
        Collection
    key : str or int
        Key or index
    default : optional
        Default value. Raise error if not provided.

    Returns
    -------
    elem
        Popped element

    """
    if isinstance(obj, dict):
        return obj.pop(key, *args, **kwargs)
    else:
        try:
            val = obj[key]
            del obj[key]
            return val
        except:
            if len(args) > 0:
                return args[0]
            else:
                return kwargs.get('default')