title: Appending a string to a variable name
body: <p><strong>This question has been edited to include the answer.</strong> </p>
  
  <p>Simple question. I would like to append a variable with the string from another variable. For example:</p>
  
  <pre><code>countries = ['USA','CAN','MEX']
  df_imp_USA = read_csv(r'%s_final_forecasts.csv' % countries[0]);
  </code></pre>
  
  <p>What syntax would allow me to automatically change <code>df_imp_USA</code> according to the contents in <code>countries</code>? I need to do this because I want to put this line into a for loop. Thanks.</p>
  
  <p><strong>Answer</strong></p>
  
  <p>As the comments suggest, using dictionaries is preferable to creating new variables. I saw this in previous answers but couldn't figure out how to use dictionaries in my code. I include the syntax below in case it may help others.</p>
  
  <pre><code>df_imp = {} # define the dic
  for country in countries:
      df_imp[country] = read_csv(r'%s_final_forecasts.csv' % country)
  </code></pre>
  
  <p>Now you can access the dict like this: </p>
  
  <pre><code>df_imp['USA']
  </code></pre>