So I have a very rudimentary understanding of python (10-week summer course split up between python and Matlab). I am trying to create a 2d list like so:
data.append (samples)
data.append (matches)
data_list.append (data)
data.clear()
This is running in a for loop and writing each time it iterates. However, when I run it and I print(data_list) I get an empty list.
I have successfully ran it like so:
data.append (samples)
data.append (matches)
data_list.append (data)
data = []
But I do not understand the difference between my two methods and why only the second one works...
samplesandmatches?data_list.append(data.copy())will solve your issue. The problem is you're putting a reference todatainsidedata_list, not the stuff insidedata. So when you cleardata, the reference insidedata_listis now pointing to an empty list.samplesandmatchesare integer values. Its a program that compares your birthday to a random sample group. So I understand how thedata_list.append(data.copy())solves this issue. It is strange that python handles that differently, because by clearing data bydata=()is preserves the values in data_list however clearing by.clearit doesn't preserve the data.