Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

function that returns a dictionary and invoke it only once and assign each property to variables

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could simply save returned object first, then assign:

obj = min_max_price()
min_prices = obj['min']
max_prices = obj['max']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading