title: How can I only ZIP certain types of files in Python?
body: <p>Let's say that that I have the following files in a folder:</p>
  <pre><code>File1.txt
  File2.py
  File3.txt
  </code></pre>
  <p>I want to create a ZIP archive, but only of the .txt files. I could use a for loop to iterate through the files of this folder, like so:</p>
  <pre><code>for folder, subfolder, files in os.walk(path):
  </code></pre>
  <p>At this point, I'm not sure how I can efficiently filter out anything that isn't a .txt file. For this example, my first thought is to walk through the directory where my files are stored, and do something like this:</p>
  <pre><code>for folder, subfolder, files in os.walk(path):
      for i in files:
          if i == 'File1.txt' OR i == 'File3.txt':
              myZip.write(i)
  </code></pre>
  <p>I think this would work since these are the only files in the folder, but it wont work if there are more files in the folder. What's a better way to only write certain types of files to a ZIP archive?</p>