def stats_quantile(data, q):
    """
        Return the specified quantile(s) q of the supplied list.
        The function can be called with either a single value for q or a
        list of values. In the latter case, the returned value is a tuple.
    """

    sx = sorted(data)
    def get_quantile(q1):
        pos = (len(sx) - 1) * q1
        if abs(pos - int(pos) - 0.5) < 0.1:
            # quantile in the middle between two values, average them
            return (sx[int(pos)] + sx[int(pos) + 1]) * 0.5
        else:
            # otherwise return the nearest value
            return sx[int(pos + 0.5)]

    if hasattr(q, "__iter__"):
        return tuple([get_quantile(qi) for qi in q])
    else:
        return get_quantile(q)