Goal : Have a function that returns a dictionary with two key values, I want to assign f()[‘x’] to a variable, and f()[‘y’] to another, and only call the function once. is it possible?
What I do invoking the function two times,but i would like to invoke it just once:
def min_max_price():
min_max_price_coins = {
min: {
"pair": 'btc',
},
max: {
"pair": 'eth',
}
}
# do stuff
return min_max_price_coins
min_prices = min_max_price()[min]
max_prices = min_max_price()[max]
Thanks so much in advance
>Solution :
You could simply save returned object first, then assign:
obj = min_max_price()
min_prices = obj['min']
max_prices = obj['max']