title: How to get a list of tuples from several text files?
body: <p>I want to access .txt files in 46 subdirectories and extract the number of 0s and 1s in the text of each file. So far I've written this code:</p>
  <pre class="lang-py prettyprint-override"><code>from pathlib import Path
  
  def count_0s(paths):
    for p in paths:
      list_zeros = []
      list_ones = []
      for line in p.read_text().splitlines():
        zeros = 0
        zeros += line.count('0')
        ones = 0
        ones += line.count('1')
      list_zeros.append(zeros)
      list_ones.append(ones)    
    return list_zeros, list_ones
  
  path = &quot;/content/drive/MyDrive/data/classes/&quot;
  paths = Path(path).glob(&quot;*/marked*.txt&quot;)
  n_zeros=count_0s(paths)
  n_zeros
  </code></pre>
  <p>I want to get the function return in the form of 2 lists (one with the number of 0s and the other with the number of 1s) to use in a Pandas dataframe.
  Sorry if the questions are duplicated.</p>