title: Efficiently removing subdirectories in dirnames from os.walk
body: <p>On a mac in python 2.7 when walking through directories using os.walk my script goes through 'apps' i.e. appname.app, since those are really just directories of themselves. Well later on in processing I am hitting errors when going through them. I don't want to go through them anyways so for my purposes it would be best just to ignore those types of 'directories'.</p>
  
  <p>So this is my current solution:</p>
  
  <pre><code>for root, subdirs, files in os.walk(directory, True):
      for subdir in subdirs:
          if '.' in subdir:
              subdirs.remove(subdir)
      #do more stuff
  </code></pre>
  
  <p>As you can see, the second for loop will run for every iteration of subdirs, which is unnecessary since the first pass removes everything I want to remove anyways.</p>
  
  <p>There must be a more efficient way to do this. Any ideas?</p>