![](https://secure.gravatar.com/avatar/25ef0a6698317c91220d6a1a89543df3.jpg?s=120&d=mm&r=g)
Aug. 4, 2016
9:24 a.m.
On Thu, Aug 4, 2016 at 11:48 AM, Victor Stinner <victor.stinner@gmail.com> wrote:
When I really need such function, I define it like this:
def clamp(min_val, value, max_val): return min(max(min_val, value), max_val)
and your colleague next door defines it like this: def clamp(min_val, value, max_val): return min(max_val, max(value , min_val)) and a third party library ships def clamp(min_val, value, max_val): return max(min(max_val, value), min_val) and combinatorially, there is at least a half-dozen more variations. The behavior of each variant is subtly different from the others. Having this function in stdlib would allow standardizing on one well-documented (and hopefully well-motivated) variant.