observer pattern class observable(object)def __init__(self)self callbacks set(self changed false def register(selfcallback)self callbacks add(callbackdef unregister(selfcallback)self callbacks discard(callbackdef unregister_all(self)self callbacks set(def poll_for_change(self)if self changedself update_all def update_all(self)for callback in self callbackscallback(selfdef main()observed observable(observer concreteobserver(observed register(lambda xobserver update( )while truetime sleep( observed poll_for_change(if __name__ ="__main__"main(the problems that the observer pattern solves are those where group of objects has to respond to the change of state in some other object and do so without causing more coupling inside the system in this sensethe observer pattern is concerned with the management of events or responding to change of state in some sort of network of objects