Let's go back to our program that computes an analytical solution to a boundary value problem. Certain parameters are required to carry out the calculation. So far, we just stored the parameter as a collection of numbers. In a more complex program, this simplistic approach could introduce subtle bugs if we accidentally used one of the parameter variables for something else.
# Define parameters k = 0.1 l = 1.0 v1 = 0.0 v2 = 1.0 t = 1.0 num_x_steps = 10 # Store parameters in a dictionary parameters = { 'diffusion coefficient' : k, 'length' : l, 'left_BC' : v1, 'right_BC' :v2, 'time' : t, 'num_x_steps' : num_x_steps } # Access the dictionary print("Value of time is {0}".format(parameters['time'])) parameters['time'] = 2.0 print("New value of time is {0}".format(parameters['time'])) print('') print("Dictionary contains {0} items:".format(len(parameters))) for key, value in parameters.iteritems(): print('{0} : {1}...