How to create a list that can not change its values, for example, i have that for loop in java:
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
if (i != j) {
List<Integer> vizinhoAplicacao = new ArrayList<>(ordemAcoes); //HERE
vizinhoAplicacao.set(i, vizinhoAplicacao.get(i) + 5);
vizinhoAplicacao.set(j, vizinhoAplicacao.get(j) - 5);
calcularRetornoAnual(vizinhoAplicacao, contatorVizinho, numeroSimulacao);
contatorVizinho++;
}
}
}
The value of ordemAcoes always stays the same as it goes into the loop, But when I make the same scenario using python, the ordemAcoes changes as I make changes to the object I declare using it, what I want to do is not to change the value of ordemAcoes, so that every time I enter the loop, I has the same values as before.
for i in range(0, 5):
for j in range(0, 5):
if (i != j):
neighborAplication = actionOrder #HERE is the list
neighborAplication[i] = neighborAplication[i] + 5
neighborAplication[j] = neighborAplication[j] - 5
returnCalculateY(neighborAplication, countNeighbor, simulationNumber)
countNeighbor += 1
Result in Java:
[35, 20, 20, 15, 10]
[35, 25, 15, 15, 10]
[35, 25, 20, 10, 10]
[35, 25, 20, 15, 5]
Result in Python:
[35, 20, 20, 15, 10]
[40, 20, 15, 15, 10]
[45, 20, 15, 10, 10]
[50, 20, 15, 10, 5]
I want to have the same result also in python, however the list actionOrder value changes when I use neighborAplication.