I'm struggling to update the values of my lists using a nested loop. My goal is to update the output lists in two waves.
The first wave: all even index lists within the order_set should be assigned to the output lists.
The second wave: all odd index lists within the order_set should be assigned to the output lists.
You'll see below that end output values are incorrect and the second wave never switches to the odd indices.
I'd appreciate any help here, I've been staring at these nested loops for too long--thank you!
End Goal Example:
# first wave:
output_1 = [1, 2, 3, 4]
output_2 = [2, 3, 4, 5]
output_3 = [3, 4, 5, 1]
output_4 = [4, 5, 1, 2]
output_5 = [5, 1, 2, 3]
# second wave:
output_1 = [1, 1, 1, 1]
output_2 = [1, 1, 1, 1]
output_3 = [1, 1, 1, 1]
output_4 = [1, 1, 1, 1]
output_5 = [1, 1, 1, 1]
# Instead, I'm seeing the following on both waves:
[4, 1, 2, 1]
[0, 5, 0, 3]
[3, 0, 1, 0]
[0, 4, 0, 2]
[5, 0, 5, 0]
The following are my variables and example code:
# First set of lists:
order_1 = [1, 2, 3, 4]
order_2 = [1, 1, 1, 1]
order_3 = [2, 3, 4, 5]
order_4 = [1, 1, 1, 1]
order_5 = [3, 4, 5, 1]
order_6 = [1, 1, 1, 1]
order_7 = [4, 5, 1, 2]
order_8 = [1, 1, 1, 1]
order_9 = [5, 1, 2, 3]
order_10 = [1, 1, 1, 1]
# Second set of lists:
output_1 = [0, 0, 0, 0]
output_2 = [0, 0, 0, 0]
output_3 = [0, 0, 0, 0]
output_4 = [0, 0, 0, 0]
output_5 = [0, 0, 0, 0]
# List of lists:
order_set = [order_1, order_2, order_3, order_4, order_5, order_6, order_7, order_8, order_9, order_10]
output_set = [output_1, output_2, output_3, output_4, output_5]
even_or_odd = 0
def assign_order(even_or_odd):
index = 0
if even_or_odd == 0:
for j in range(0, len(order_set), 2):
for i in range(len(output_set)-1):
if index < 5:
output_set[index][i] = order_set[j][i]
index += 1
else:
index = 0
output_set[index][i] = order_set[j][i]
even_or_odd = 1
elif even_or_odd == 1:
for j in range(1, len(order_set), 2):
for i in range(len(output_set)-1):
if index < 5:
output_set[index][i] = order_set[j][i]
index += 1
else:
index = 0
output_set[index][i] = order_set[j][i]
even_or_odd = 1
print("Original Output:")
for i in range(len(output_set)):
print(output_set[i])
print("Order Set")
for i in range(len(order_set)):
print(order_set[i])
assign_order(even_or_odd)
print("Even Output:")
for i in range(len(output_set)):
print(output_set[i])
assign_order(even_or_odd)
print("Odd Output:")
for i in range(len(output_set)):
print(output_set[i])