I have a variable which is constantly changing, and I want to store all the previous values of the variable into a list, however in the code below when I try to append to the list, it just replaces the number in the list to the current value of the variable, and the length of the list is always remaining at one
while True:
degrees = []
a = get_baering_in_degrees()
degrees.append(a)
print(len(degrees))
print(degrees)
In this case, get_bearing_in_degrees() is a function which returns a value that is constantly changing, and when I print the length of the degrees list, it just stays at 1. Also, this code constantly loops for a set duration, but here I've just represented it using a while true loop.
You need to define degrees = []
outside of the while loop.
Something like this:
degrees = []
while True:
a = get_baering_in_degrees()
degrees.append(a)
print(len(degrees))
print(degrees)