I have a function that returns a dict of pandas dataframes. The dict has a key and the key for each dataframe is its corresponding name.
def fun(inputs): x = calculations y = calculations z = calculations, etc. return: {'name1':x,'name2':y,'name3':z} I would like to use some of these dataframes as variables elsewhere in my code. To do this, I currently do the following:
x = fun() var1 = x['name1'] var2 = x['name2'] var3 = x['name3'] and so on. I would like to do this more efficiently (fewer lines of code). In my mind, I should be able to do something like this:
[var1,var2,var3] = fun() But this just assigns each name to each variable as a string. Can this be done? or should my function output be setup differently?
['']keys all the time is awkward, it makes your statements bulkier, and your IDE won't be as helpful with dict entries as with variables.[var1,var2,var3] = fun()how does this in any way take advantage of the nice properties of dictionaries we all know and love?