Issue
Say I have a function, denoted by Show, that runs by accessing points in a list. Is it then possible to assign each outcome from the function to a variable? Is it possible for the variable to be defined by dfi so the outputs would be df1, df2, df3, ect... for a long as defined by count?
count = 5
for i in range(0, count):
d = Show(list[i])
Solution
You can do this using a dict by storing variables as keys. A sample could be like this:
count = 5
dic = {}
for i in range(count):
#create key, that would be the variable
k = "df{}".format(i)
dic[k] = show(list[i])
And now you can use dict to fetch and use the variables in O(1) which would be same as if you have defined the variables explicitly and stored them.
Answered By - avats
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.