Peter Otten at 2016/11/19 5:40:34PM wrote:
> And now for something completely different ;)
>
> What if you only record the changes to the list? For a long list that would
> save space at the expense of calculation time. For example:
Excellent! Although not 100% fit into my application, I must
jf...@ms4.hinet.net wrote:
> I have a working list 'tbl' and recording list 'm'. I want to append 'tbl'
> into 'm' each time when the 'tbl' was modified. I will record the change
> by append it through the function 'apl'.
>
> For example:
>
tbl=[0,0]
m=[]
>
tbl[0]=1
apl(tbl)
Oh, I don't know slice well enough:-(
So, slice tbl[:] will create a new object (a copy of tbl) which can be passed
as a function argument
m.append(tbl[:])
or bind to a new name
w=tbl[:]
or re-bind to itself
w[:]=tbl
Thanks you, Ian and Steve.
Steve D'Aprano at 2016/11/19 11:01:26AM wrote:
>
On Sat, 19 Nov 2016 12:44 pm, jf...@ms4.hinet.net wrote:
> I have a working list 'tbl' and recording list 'm'. I want to append 'tbl'
> into 'm' each time when the 'tbl' was modified. I will record the change
> by append it through the function 'apl'.
[...]
> Obviously the most intuitive way
On Nov 18, 2016 6:47 PM, wrote:
I have a working list 'tbl' and recording list 'm'. I want to append 'tbl'
into 'm' each time when the 'tbl' was modified. I will record the change by
append it through the function 'apl'.
For example:
>>>tbl=[0,0]
>>>m=[]
>>>tbl[0]=1
I have a working list 'tbl' and recording list 'm'. I want to append 'tbl' into
'm' each time when the 'tbl' was modified. I will record the change by append
it through the function 'apl'.
For example:
>>>tbl=[0,0]
>>>m=[]
>>>tbl[0]=1
>>>apl(tbl)
>>>m
[[1,0]]
>>>tbl[1]=2
>>>apl(tbl)
>>>m