I tried this:
listing = []
entry = [0.0]*2
entry[0] = 1.0
entry[1] = 2.0
listing.append(entry) # My first entry
entry[0] = 2.0
entry[1] = 3.0
listing.append(entry) # Another entry
The above does not work. The same entry pointer is retained, so updating the entry also updates the [1.0, 2.0] entry of the listing. I can get it to work with this:
entry[0] = 1.0
entry[1] = 2.0
listing.append(entry) # My first entry
entry = [0.0]*2
entry[0] = 2.0
entry[1] = 3.0
listing.append(entry) # Another entry
entry = [0.0]*2
But that seems clunky. Is there a cleaner way of doing this?
Update: (Which cuts through the chatter of the question this duplicates) The best way to do this, at least for Python 3.X users, is:
listing.append(entry.copy())