2
Considering the lists:
lista1=["a","b","c","d"]
lista2=[5,6,7,8]
My goal is to get a new list that has the elements of these two ['a', 'b', 'c', 'd', 5, 6, 7, 8]
, but preserving them the way they are.
Making lista3=[lista1,lista2]
, what I got is a list of lists [['a', 'b', 'c', 'd'], [5, 6, 7, 8]]
, which is of no interest to me.
I tried to do it this way:
lista4=lista1
lista4.extend(lista1)
print(lista4)
Upshot:
['a', 'b', 'c', 'd', 5, 6, 7, 8]
This resulted in what I expected. But by asking lista1
again, it was no longer with the initial configuration, but with the same result above.
print(lista1)
['a', 'b', 'c', 'd', 5, 6, 7, 8]
I thought that using lista4=lista1
and use .extend()
in list 4, the lista1
would be as set at the beginning. Could someone explain to me why this occurred and if it has how to get around?
I am used to using R software and it accepts this type of operation, so I got a little lost. Thank you very much for the explanation! It was very educational!
– Rodrigo Abreu