python dict update diff
        Posted  
        
            by adam
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by adam
        
        
        
        Published on 2009-04-03T19:04:34Z
        Indexed on 
            2010/05/25
            12:11 UTC
        
        
        Read the original article
        Hit count: 415
        
Does python have any sort of built in functionality of notifying what dictionary elements changed upon dict update? For example I am looking for some functionality like this:
>>> a = {'a':'hamburger', 'b':'fries', 'c':'coke'}
>>> b = {'b':'fries', 'c':'pepsi', 'd':'ice cream'}
>>> a.diff(b)
{'c':'pepsi', 'd':'ice cream'}
>>> a.update(b)
>>> a
{'a':'hamburger', 'b':'fries', 'c':'pepsi', 'd':'ice cream'}
I am looking to get a dictionary of the changed values as shown in the result of a.diff(b)
© Stack Overflow or respective owner