0

I've been a javascript dev for many years and I'm just now starting to learn Python. This seems like it should work, but for some reason I get the error:

local variable 'var_a' referenced before assignment

    var_a = 0
    var_b = 0
    var_c = 0
    def accumulate(tup):
        var_a += tup[3]
        var_b += tup[4]
        var_c += tup[5]
        return (tup[0], var_a, var_b, var_c)
    insert = list(map(accumulate, output))
    print(insert[-5:])

Maybe there's also a much better way of doing this. I also tried using the keyword nonlocal, but my compiler didn't even let me run that.

Clearly there's something very basic I don't understand.

0 Answers0