Looking for a short way of doing a division where the large number is always the numerator. Is there a simpler way of doing it other than this?
def divide(A, B): if A > B: return A/B else: return B/A
If you don’t like
if statements and you want to avoid redundant comparisons, then you can do this:
from operator import truediv def divide(a, b): return truediv(*sorted([a, b], reverse=True))
Or, alright, the slightly less silly way of doing this:
def divide(a, b): a, b = sorted([a, b]) return b / a
But… don’t. Your way is the simplest, most obvious way to do it.