def pop(obj, key_name=None):
    """
    Remove the indexed item from the collection and return the removed value. Similar to dict.pop(key_name).
    :param obj:
    :param key_name: key name or index
    :return:
    """
    if key_name is None:
        if isinstance(obj, list):
            return obj.pop()
        k, v = obj.popitem()
        return v
    return obj.pop(key_name)