Looking for simpler way of dividing 2 numbers A and B where the largest is always the numerator

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

Answer

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.