def tooltip_formatter(s, subset, fmt, style):
    """Function to generate tooltips from a pandas Series
    
    Parameters
    ----------
    s : pandas.Series
        Row in the internal pandas DataFrame
    subset : list
        Subset of columns that are used for the tooltip
    fmt : str
        Format string for each key-value pair of the tooltip
    style : dict
        CSS styling applied to each item independently
    """
    items = []
    for k, v in s[subset].to_dict().items():
        v = f'<span style="{style[k](v)}">{v}</span>' if style.get(k) else v
        items.append(fmt.format(key=k, value=v))
    return "<br>".join(items)