[off-topic] Pessimal (was: Detecting changes to a dict)

2009-09-29 Thread John Posner
If you can enumerate the language of possible inputs you could generate a unique binary representation. Against a language of size l that would only take you O(l*n) to build the repr for a dict and for certain repr sizes the comparison could be O(1), making the entire operation O(l*n+l*m) vs

Re: Detecting changes to a dict

2009-09-28 Thread CTO
On Sep 28, 1:11 am, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: On Sun, 27 Sep 2009 21:42:10 -0700, CTO wrote: Is there a fast way to see that a dict has been modified? ... d = {a: b, c: d} d2 = d.copy() assert d == d2 d[e] = f assert d == d2 Is this what you're

Re: Detecting changes to a dict

2009-09-28 Thread Duncan Booth
Steven D'Aprano st...@remove-this-cybersource.com.au wrote: Is there a fast way to see that a dict has been modified? I don't care what the modifications are, I just want to know if it has been changed, where changed means a key has been added, or deleted, or a value has been set.

Re: Detecting changes to a dict

2009-09-28 Thread Scott David Daniels
Steven D'Aprano wrote: I'm pretty sure the answer to this is No, but I thought I'd ask just in case... Is there a fast way to see that a dict has been modified? ... Of course I can subclass dict to do this, but if there's an existing way, that would be better. def mutating(method): def

Re: [off-topic] Pessimal (was: Detecting changes to a dict)

2009-09-28 Thread geremy condra
On Mon, Sep 28, 2009 at 9:53 AM, John Posner jjpos...@optimum.net wrote: If you can enumerate the language of possible inputs you could generate a unique binary representation. Against a language of size l that would only take you O(l*n) to build the repr for a dict and for certain repr

Re: [off-topic] Pessimal (was: Detecting changes to a dict)

2009-09-28 Thread geremy condra
Aaagh! Did it without thinking. Should be O(S*N) and O(S*2N). On Sep 28, 2009 12:09 PM, geremy condra debat...@gmail.com wrote: On Mon, Sep 28, 2009 at 9:53 AM, John Posner jjpos...@optimum.net wrote: If you can enumera... 1) I honestly wouldn't know, seeing as how I wasn't alive ;). 2)

Detecting changes to a dict

2009-09-27 Thread Steven D'Aprano
I'm pretty sure the answer to this is No, but I thought I'd ask just in case... Is there a fast way to see that a dict has been modified? I don't care what the modifications are, I just want to know if it has been changed, where changed means a key has been added, or deleted, or a value has

Re: Detecting changes to a dict

2009-09-27 Thread Simon Forman
On Sun, Sep 27, 2009 at 5:36 AM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: I'm pretty sure the answer to this is No, but I thought I'd ask just in case... Is there a fast way to see that a dict has been modified? I don't care what the modifications are, I just want to know

Re: Detecting changes to a dict

2009-09-27 Thread geremy condra
On Sun, Sep 27, 2009 at 5:36 AM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: I'm pretty sure the answer to this is No, but I thought I'd ask just in case... Is there a fast way to see that a dict has been modified? I don't care what the modifications are, I just want to know

Re: Detecting changes to a dict

2009-09-27 Thread CTO
On Sep 27, 5:36 am, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: I'm pretty sure the answer to this is No, but I thought I'd ask just in case... Is there a fast way to see that a dict has been modified? I don't care what the modifications are, I just want to know if it has

Re: Detecting changes to a dict

2009-09-27 Thread Steven D'Aprano
On Sun, 27 Sep 2009 21:42:10 -0700, CTO wrote: Is there a fast way to see that a dict has been modified? ... d = {a: b, c: d} d2 = d.copy() assert d == d2 d[e] = f assert d == d2 Is this what you're looking for? In general, no. I was hoping for an O(1) check. Yours test is only O(1)