-1
Good afternoon,
I have the following problem:
I have a list of tuples called list_chromosomes, with 10 positions.
I want to open a new position at the end of it (11th position), where it will initially equal the first. For that I used
lista_cromossomos.append.(lista_cromossomos[0])
Upshot:
[[1, 0, 0, 0], .. , [1, 0, 0, 0]] -> 11 terms, where the first and the last are equal
I want to multiple only the components of the last term by 7 to stay [7, 0, 0, 0], so the expected is:
Expected result:
[[1, 0, 0, 0], .. , [7, 0, 0]]
For that I used:
for y in range(0, len(lista_cromossomos[10])):
lista_cromossomos[10][y] = lista_cromossomos[10][y] * 7
It turns out that instead of multiple just the last tuple, it multiple the last and the first.
Code result:
[[7, 0, 0, 0], .. , [7, 0, 0]] -
What’s wrong with it?
Very good, partially solved. In the complete case it is a class, where the first attribute is this "chromosome", and the second is a float number. When I use this in the float the following error appears: 'float' Object has no attribute 'copy' I did so:

classe[10].cromossomo =classe[0].cromossomo.copy -> Funciona
classe[10].numero = classe[x].numero.copy -> Não funciona

You know why?– Gabriel Albuquerque
The method
copy()
exists only for objects oflist()
,dict()
andset()
(may exist for other objects). What I said about "memory addresses" is not applied to values of primitive types, so unlike the example I showed in the answer, when making the codeinteiro2 = inteiro1
, a new value would be created and assigned to the variable. Therefore, there is no reason to have a methodcopy()
for primitive types.– JeanExtreme002