def limit(val, bottom=None, top=None):
    """
    Will return a copy of @val in such a way that:
    If @bottom is not None, the result will be no less than @bottom;
    If @top is not None, the result will be no more than @top.

    >>> limit(10)
    10
    >>> limit(10, 1)
    10
    >>> limit(10, 15)
    15
    >>> limit(10, 1, 8)
    8
    >>> # Can be used with anything that can be compared using max() and min()
    ... limit('6', top='3')
    '3'

    AUTHORS:
    v0.4.5+             --> pydsigner
    """
    uval = val
    if bottom is not None:
        uval = max(uval, bottom)
    if top is not None:
        uval = min(uval, top)
    return uval
