I am having the following code:
file = open('MyCSV.csv') # this read the Headers name
reader = csv.reader(file)
Data = next(reader,None)
Data = Data[1:]
DataTmp = Data
for item in DataM: # DataM is a list with one element from Data
Data.remove(item) #remove one item
#
print(len(Data))
print(len(DataTmp))
So, I open MyCSV.csv
file, read the header line, and store it in the variable Data
. I also made a copy of Data
by DataTmp
. Originally, the list Data
has 10 elements.
Then, I removed one element from Data
.
Now, I expect that the length of Data
is 9
and the length of DataTmp
is still 10
. However, I get the answer that the length of DataTmp
is 9
too. Why? I never changed DataTmp
and I defined it before I remove an element from Data
.
Thanks for your help!