'2 dictionaries which track the same value. How to implement an observer method to update each other?

I am creating 2 dictionaries which map connections between cells (which are defined at a specific point) to an input space. For example, below I generate a map for a cell at position (8,8) to connect to points one of which is (0,4) this connection is given a weight of 4. However, I also need to store a reciprocal mapping so at point (0,4) is linked to cell (8,8) and needs to have the same weight bc they are the same link between points.

**(8.0, 8.0)**: [{(3, 5): 6},
              {(9, 0): 5},
              {(7, 2): 8},
              {(4, 1): 5},
              {(7, 3): 5},
              **{(0, 4): 4},**

 **(0, 4)**: [{(0, 1): 5},
          {(4.0, 4.0): 8},
          {(1.0, 4.0): 2},
          {(1.0, 8.0): 1},
          {(8.0, 8.0): 4},
          **{(8.0, 4.0): 8}],**

I am able to create the reciprocal mapping with no trouble (see code below) and this works well. However, now I would like to be able to change the weight accessing it from either dictionary and have the other update in tandem. I'm almost certain I need to implement some sort of Observer design pattern to generate this but I'm not sure how to go about it since the value being tracked is nested into the dictionary/list(s). What would be the easiest way to accomplish this observer behavior?

# build base chandelier cell map to input space
for center in self.ChC_Coordinates:
    percent_connected = np.random.randint(30,50)
    board = np.zeros((self.HT, self.WD), dtype=bool)
    N_points = min(round(board.size * percent_connected/100), 1200)
               # 1200 is appx biological chc_connection value for ChC
    dist_char = 35 # distance where probability decays to 1/e
    flat_board = board.ravel()
    endpoints = []
    while N_points:
        idx = rng.integers(flat_board.size)
        while flat_board[idx]:
            idx += 1
            if idx >= flat_board.size:
                idx = 0
        if not flat_board[idx]:
            pt_coords = (idx // board.shape[0], idx % board.shape[0])
            point = np.array(pt_coords) # to enable distance calculation
            dist = np.sqrt(np.sum((center-point)**2))
            P = np.exp(-dist/dist_char)
            if rng.random() < P:
                flat_board[idx] = True
                synapse_wght = np.random.randint(1,9)
                endpoints.append({pt_coords: synapse_wght})
                N_points -= 1
    self.ChCs[center] = endpoints

# build reciprocal map of input space to attached chandelier cells
self.build_Reciprocal_Map_Of_Input_To_ChC()

return self.ChCs, self.PyC

def build_Reciprocal_Map_Of_Input_To_ChC(self):
    for point in self.PyC_points:
        attached_chcs = []
        # Generate initial reciprocal mapping of input to ChCs
        for chc_point,connected_points in self.ChCs.items():
            for attached_point in connected_points:
                chc_points_in_use = set()
                if point in attached_point.keys():
                    synapse_wght = list(attached_point.values())[0]
                    attached_chcs.append({chc_point: synapse_wght})
                    chc_points_in_use.add(chc_point)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source