def get_key(f, *args, **kwargs):
    """
    Returns a unique key for a memoized function.

    Args:
        f: the function
        args: positional arguments
        kwargs: keyword arguments
    Returns:
        The key.
    """

    if len(args) > 0:
        kwargs["#args"] = ",".join(map(str, args))

    sorted_keys = sorted(kwargs)
    arg_key = "&".join(
        ["{}:{}".format(key, kwargs[key]) for key in sorted_keys])

    key = "{}.{}${}".format(f.__module__, f.__name__, arg_key).replace(" ", "~")

    return key