How do I save results of a “for” loop into a single variable?

后端 未结 2 1026
傲寒
傲寒 2020-12-03 22:57

I have a for loop:

for x in range(1,13):
   print (\"This was the average temperature in month number \" + str(x) + \" in Boston, 2014: \", Boston_monthly_te         


        
2条回答
  •  广开言路
    2020-12-03 23:48

    You could simply store the results in a dictionary, pickle that and store it:

    import pickle
    
    d = {}
    for x in range(1,13):
       d[x] = Boston_monthly_temp(x)
    res = pickle.dumps(d)
    # write res to a file
    

提交回复
热议问题