I'm just playing around with a local k8s cluster and created a simple app to containerize. I just want to print a reversed array. Disclaimer: I might be using the words "lists" and "arrays" interchangeably here :)
So I defined two utility functions: one to generate lists with random int values and one to reverse said lists.
from random import randint
def reverse_array(input):
i=0
arr_length = len(input)
last_index = arr_length - 1
while i < arr_length / 2:
temp = input[i]
input[i] = input[last_index - i]
input[last_index - i] = temp
i=i+1
return input
def generate_random_array(max_iteration):
return [randint(0, 100) for _ in range(0, max_iteration)]
Both methods have unit tests, so I know they're working as intended
then I execute them in the main app:
import util.misc as misc
from time import sleep
while True:
input_arr = misc.generate_random_array(5)
reversed_arr = misc.reverse_array(input_arr)
# adding manual and control only for debugging
manual = [1, 2, 3]
control= misc.reverse_array(manual)
print(f"your original array is {input_arr}")
print(f"your reversed array is {reversed_arr}")
print(f"control is {control}")
sleep(1)
Oddly enough, the application's output shows reversed_arr
actually has the same order as input_arr
, but control
is correctly reversed.
your original array is [27, 95, 0, 91, 13]
your reversed array is [27, 95, 0, 91, 13]
control is [3, 2, 1]
What is going on here? It seems that arrays produced by generate_random_array
are actually immutable