Here's some code that will handle any number of arguments. It first sorts the argument names into alphabetical order. Then it creates all pairs of arguments and performs the divisions (with the value of the earlier arg in alphabetical order being divided by the value of the later one), storing the results in a dict
, with the dict
's keys being constructed by the concatenating the argument names. The function returns the constructed dict
, but of course in your code you may wish to perform further actions on it.
from itertools import combinations
def ratios(**kwargs):
pairs = combinations(sorted(kwargs.keys()), 2)
return dict((p + q, kwargs[p] / kwargs[q]) for p, q in pairs)
print(ratios(a=600, b=3, c=2))
output
{'ac': 300.0, 'ab': 200.0, 'bc': 1.5}