Consider the following function:
def absolute_value(some_number):
if some_number < 0:
return -some_number
return some_number
and this one:
def absolute_value(some_number):
return (some_number**2)**0.5
We can say that (in a naive manner) these two more or less achieve the same result (ignoring the performance issues) but the latter one has less cyclomatic complexity due to lack of the conditional. What I want is, for the sake of reduced cyclomatic complexity, I want to implement the following function without the conditional:
def limit(some_number):
if some_number > 1
return 1
return some_number
Is there an elegant way of doing this?
Thank you for your interest.