''' def encode_rle(flat_data):
rle_complete = []
run_length = 0
num_variables = count_runs(flat_data)
# goes through each value in flat_data
for item in flat_data:
if item not in rle_complete: # if item is not in blank list then it is added
rle_complete.append(item)
x = 0
# current item in rle_complete is the first value
current = rle_complete[x]
rle_final = []
for item in rle_complete: # for each value in rle_complete
for item in flat_data: # for each value in original data
if current == item:
run_length += 1 # add a value to count
else: # when current value in rle_complete stops being
# the same as the current value in flat_data the rle_final is updated
rle_final.extend([run_length, current])
current = rle_complete[x + 1]
run_length = 1
num_variables -= 1
if num_variables == 0:
break
return rle_final
'''
I am using the latest version of python and pycharm. When it comes to my code the function works if I use the input [15, 15, 15, 4, 4, 4, 4, 4, 4] I get the correct output [3, 15, 6, 4]. However when I change the input to anything else like [15, 15, 15, 4, 4, 4, 4, 4, 5] the output is completely wrong and different. Any help would be appreciated. The count_runs function that you see in my code simply counts the amount of unique variables within the input.