title: How to access a dictionary produced within a function, outside the function, without calling the function more than once. PYTHON
body: <p>I have a function that returns a dictionary. </p>
  
  <p>I would like to be able to access and work with that dictionary many times in the code, without the need to be calling the function that produces that dictionary every time. In other words, call the function once, but work with the dictionary that it returns many times.</p>
  
  <p>So this way, the dictionary is constructed only once (and maybe stored somewhere?), but called and utilised many times in the script.</p>
  
  <pre><code>def function_to_produce_dict():
      dict = {}
      # something
      # something that builds the dictionary 
      return dict 
  
  
  create_dict = function_to_product_dict()
  
  # other code that will need to work with the create_dict dictionary. 
  # without the need to keep constructing it any time that we need it. 
  </code></pre>
  
  <p>I have read other posts such as: 
  <a href="https://stackoverflow.com/questions/19326004/access-a-function-variable-outside-the-function-in-python-without-using-global">Access a function variable outside the function without using `global`</a></p>
  
  <p>But I am not sure that by declaring the dictionary as global withing the function_to_produce_dict() is going to make the dictionary accessible without having to build it every time, by calling the function again and again. </p>
  
  <p>Is this possible? </p>