def assoc(key, val, obj=None):
    """Add ("associate") "val" as "key" to "obj". "obj" should be a
    dictionary-like object; if it is None, then a new empty dict will be
    created. The return value will always be a dict, casting the original
    argument as needed.
    """
    new_obj = {} if obj is None else dict(obj)
    new_obj[key] = val
    return new_obj
