1

I have a function which does the following computation and then saves the data in the dictionary. The function is called several time through a loop.

el_flip = self.element_flip(element_data)
    avg = np.array(el_flip[1])
    flip = np.array(el_flip[0])
   
    self.updated_element_data={}
    self.updated_element_data.update({})
    self.updated_element_data['avg'+self.elem_name+self.elem_path]=[avg]
    self.updated_element_data['flip'+self.elem_name+self.elem_path]=[flip]
    self.updated_element_data['orig'+self.elem_name+self.elem_path]=[element_data]

    print('dict',self.updated_element_data)

I tried using the update function, but it does not seem to help. I want each time this function is called, new values are computed and they should be added in the dictionary, rather they are over written.

Here, values for elem_name, elem_path, [avg,flip,element_data] change for each function call.

  • you always create a new empty dict when you call this code (lines 4 and 5), you want to do something like [here](https://stackoverflow.com/questions/3199171/append-multiple-values-for-one-key-in-a-dictionary) – Ruli Nov 04 '20 at 12:14
  • oh yes, I am creating a new dict every time...thank you for the help.. :) – user14447985 Nov 04 '20 at 12:36

0 Answers0