title: How to set a variable equal to another local variable inside a function by passing an external argument to the function?
body: <p>The below code snippet works fine for generating a random forest with a varying number of min_samples_leaf.</p>
  
  <pre><code>for x in [12,14,16,18]:
      rf = ensemble.RandomForestClassifier(n_estimators=2000,max_depth=None,criterion='entropy',
                                                                                max_features=5, n_jobs=-1, random_state=0,
                                                                                verbose=0,oob_score=True,bootstrap=True,
                                                                                min_samples_leaf =x)
  </code></pre>
  
  <p>Similarly, I want to vary other parameters, say max_features, then the code will change to-</p>
  
  <pre><code>for x in [12,14,16,18]:
      rf = ensemble.RandomForestClassifier(n_estimators=2000,max_depth=None,criterion='entropy',
                                                                                max_features=x, n_jobs=-1, random_state=0,
                                                                                verbose=0,oob_score=True,bootstrap=True,
                                                                                min_samples_leaf =14)
  </code></pre>
  
  <p>This also works fine, with the generalization being, I have to set as "x" the parameter I want to loop. keeping this in mind I have written this function -</p>
  
  <pre><code>def forest_tuning(parameter,tree,crit,mf,rs,msf):
  #Some Codes here
      for x in parameter:
          rf = ensemble.RandomForestClassifier(n_estimators=tree,max_depth=None,criterion=crit,
                                                                                    max_features=mf, n_jobs=-1, random_state=rs,
                                                                                    verbose=0,oob_score=True,bootstrap=True,
                                                                                    min_samples_leaf =msf)
      #Some Codes here
  #Function call
  p=forest_tuning(parameter=[40,50],tree=2000, crit='entropy',mf=5,rs=0,msf=x)  
  </code></pre>
  
  <p>I have set variable (msf) as "x", the counter variable to replicate the first code. This approach isn't working, as the "x" passed is not able to bind with the counter variable.</p>
  
  <p>I am not able to pass an argument to a function, and trick the function to treat it as a local variable.The static "x" is local, and one passed is global hence the problem .</p>
  
  <p>I can think of statically placing "x" as in 1st 2 codes, but then I lose the flexibility and compactness of passing arguments in a function.</p>
  
  <p>Please help me with generalizing this for loop with a function.</p>