#!/usr/bin/env python # -*- coding: utf-8 -*- def clamp(n, minn, maxn): """Clamp a number between a max and a min value. :param n: Number to clamp. :param minn: Minimum number to allow. :param maxn: Maximum number to allow. """ return max(min(maxn, n), minn)