Recursively call a function with **kwargs

Earlier today, I posted this question in which I have this recursive function:

def add_to_smallest(kwargs): if len(list(set(list(kwargs.values())))) == 1: print("all values in dict are the same") print(kwargs) return kwargs else: index = min(kwargs.values()) for key, value in kwargs.items(): if value == index: kwargs[key] += 1 add_to_smallest(kwargs) add_to_smallest({"pos1": 60, "pos2": 54, "pos3": 300, "pos4": 5})

This functions purpose in live is to add to the smallest number in the dictionary until all values are equal.
I am passing a dictionary Items as an argument, but Ideally I would want to pass key word arguments via the ** operator, which can be done for the first function call in the call stack (again, the function is recursive) the trouble begins when I want to recall the function with the modified arguments. kwargs is now a dictionary, how can I break that down and pass it to the function call where each key value pair takes the form of a key word argument and it’s value?

You would need to unpack the dictionary:

4. More Control Flow Tools — Python 3.9.6 documentation

1 Like

Funny how obvious ot seems after it’s been pointed out… :stuck_out_tongue_winking_eye:
Thanks again!