title: How to get data from list of dict on basis of string
body: <p>I have a list of dictionaries that looks like this:</p>
  <pre><code>data = [{'name': 'root/folder1/asd/file.csv'},
          {'name': 'root/folder1/bsd/file.csv'}, 
          {'name': 'root/folder1/folder2/folder3/new.csv'}, 
          {'name': 'root/folder1/folder2/folder3'}]
  </code></pre>
  <p>I want to take this list and pare it down to include only files that have a certain extension and exist in the shallowest folder in the list. That is, if a path has two <code>/</code> in it, and all other paths have at least two, then filter out all paths that have more than two. If the smallest number of slashes is three, then filter out anything with more than three.</p>
  <p>This is what I started with:</p>
  <pre><code>for path in data:
      if path.get('name').endswith('.exe') or path.endswith('.csv'):
         path_count = len(re.findall('/', path)) 
         path.update({'path_count': path_count})
  </code></pre>
  <p>Now I will check minimum count by again applying a for loop. Is there a cleaner way to do this?</p>