So -
what you want to do is confused
How Voce is doing is confusing (you put a code "more or less like this", but it doesn’t have everything that is happening) - and you could have given some concrete explanation of how your data looks.
But, at last, the excerpt of code that you presented there shouldn’t present the problem you describe.
Your problem is this: you are inserting the same object (a list) as a list item in more than one place.
If you do it in Python:
In [86]: a = ["a", ]
In [87]: b = [a, a]
In [88]: b
Out[88]: [['a'], ['a']]
In [90]: a.append("b")
In [91]: b
Out[91]: [['a', 'b'], ['a', 'b']]
Note that within the list b
the list a
is present twice - is the same object. So when I change the list a
, is expected to in b
what I entered appears in both elements. No surprise there.
In your code, you must be doing this, directly or indirectly. But in the snippet that you pasted above, that doesn’t happen - you recreate the list movi_anexos
as a new object, in each iteration of its first for
, for example.
Python has a syntax that allows you to create a copy of a list by referencing it that may help you:
When inserting a list as an item of another, instead of just the variable name, put that you want a slice (Slice) from the beginning to the end of the list being inserted (ask for the elements [:]
a slice omitting the initial and final elements implies a slice from beginning to end) . List slices are copies of the original list, and a copy from beginning to end is nothing less than a copy of the list.
So if you write code like:]
movimentacoes.append([data, texto, movi_anexos[:])
shall avoid that the same list is present in more than one position in its data structures. (but I emphasize that in the passage that is here this would not happen - but I do not know for example if your data
and texto
are lists too - if they are, give them the same treatment)
And finally, unrelated to your doubt: the way you’re trying to organize this data seems very problematic - you’re going to have a sopa
of lists within lists, without defined length, without defined depth - it seems the worst nightmare to be able to recover anything later.
Remember that there are also dictionaries, and above all, you can create your own classes that will gauge your information very well structured and can help you work with the data you have.
I didn’t quite understand, I would like to define values in
lista[0]
in the case of the first list of lists that appears, make the append of another list, which are links, is that it? It would be for examplelista[0].append([link1, link2])
, this way would have laterlista[0] = ['dado11', 'dado12', [link1, link2]]
– Miguel
This, but for example, the movi_attachments always gives append in the links that exist, so every time I have a new list in the movement list, it brings me the attachments of the previous ones in the current one.. Understands?
– Vanessa Nunes