[Python-ideas] Consider adding clip or clamp function to math

Steven D'Aprano steve at pearwood.info
Thu Aug 4 20:55:29 EDT 2016


On Thu, Aug 04, 2016 at 01:21:27PM -0700, Chris Kaynor wrote:

> I was curious about what the likely cases are in many cases, so I ran a
> quick sample from a professional project I am working on, and found the
> following results:
[...]
> As would be expected, all cases were using computed value as the input,
> only the min/max were ever constant.

Thanks for doing that Chris. That's what I expected: I can't think of 
any use-case for clamping a constant value to varying bounds:

x = known_value()
for lower, upper in zip(seq1, seq2):
    y = clamp(x, lower, upper)
    process(y)



-- 
Steve


More information about the Python-ideas mailing list