Home > Back-end >  Write values returned from function as a list
Write values returned from function as a list

Time:04-24

I have a function:

    difference(values[["x","y"]],n,m)

which calculates the difference between x and y for year n and n 1 between years 2010 and 2020. For example,

    difference(values[["x","y"]],2010,2011)

returns an arbitrary number 5.

I wish to write this so that it calculates the difference between x and y for every n and n 1, for example all of the following

    difference(values[["x","y"]],2010,2011)
    difference(values[["x","y"]],2011,2012)
    difference(values[["x","y"]],2012,2013)
    ...
    difference(values[["x","y"]],2019,2020)

written as a list. I have tried this:

    for i in range(2010, 2021):
        print(difference(values[["x","y"]],i,i 1))

but it clearly doesn't work.

CodePudding user response:

for i in range(2010, 2021):
        print(difference(values[["x","y"]],i,i 1))

In this loop i takes as value only 2010. range with 2 arguments take the min and max. You should use range(2010, 2020)

  • Related