title: Nested for loops not resetting python
body: <p>I am new to python and am finding it much harder to work with for loops than in R!</p>
  <p>Here is an example of my code:</p>
  <pre><code>import pandas as pd
  import os
  
  
  insight_numbers = list(range(379, 397))
  
  insights = [&quot;insight.&quot; + str(number) for number in insight_numbers]
  
  #List insight files
  folder = (&quot;path\\to\\data&quot;)
  
  individual_insight_files = []
  for insight in insights:
      individual_insight_files.append(str(folder)  + '\\'+ str(insight) +'.csv')
  
  #Initialize empty lists for use in loops
  user_files = []
  user_data_list = []
  
  #Outer loop - reads each larger file
  for insight in individual_insight_files:
      if not os.path.isfile(insight):
          continue
      try: 
          insight_raw = pd.read_csv(insight)
      except: 
          print(str((insight))) + 'Errored out' 
          continue
      
      ids = insight_raw.PERSON_ID
      
      #Middle loop - identifies user csvs
      for user in ids:
          user_files.append(str(folder)  + '\\'+ str(user) +'.csv')
                  
          #Inner loop - puts results of user csvs into list
          for uf in user_files:
              if not os.path.isfile(uf):
                  continue
              try: 
                  user_file = pd.read_csv(uf)
              except: 
                  print(str((uf))) + 'Errored out' 
                  continue
              
              print(user_file)
              
              user_data_list.append(user_file)
                          
  </code></pre>
  <p>The issue I'm having is that the loop works fine for the first insight file but where the &quot;ids&quot; variable should change with each new insight in the outer loop, it doesn't reset. Sorry I know this is a basic question but I am really stuck! Any advice appreciated.</p>