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

Try this

result = []
for x in range(1,13):
    result.append((x, Boston_monthly_temp(x)))

Now result contains the x and avg

>>> for x, avg in result:
...     print ("This was the average temperature in month number " + str(x) + " in Boston, 2014: ", avg)
...
This was the average temperature ...
This was the average temperatu ...
[...]

Leave a Comment