code: def all_headers_matching(match_regex):
      rhl = [h for h in raw_header_list if match_regex.match(h)]
  
      # Sometimes filenames may have multiple versions, which we need to handle.
      # We can do this splitting the list into two components -- those that are
      # unique, and those that need additional path information to distinguish
      # which one is being included.  The latter we then expand out the directories
      # until all files are correctly included
      def separate_unique(raw_headers, n):
          lookup = defaultdict(lambda: [])
  
          for h in raw_headers:
              fn = "/".join(h.split("/")[-n:])
              lookup[fn].append(h)
  
          header_list = []
  
          for fn, hl in lookup.items():
              if len(hl) == 1:
                  header_list.append((fn, hl[0]))
              else:
                  # use recursion on this sublist to find distinguishing suffixes
                  header_list += separate_unique(hl, n + 1)
  
          return header_list
  
      header_list = separate_unique(raw_header_list, 1)
  
      assert len(raw_header_list) == len(header_list)
      assert len(header_list) == len(set(header_list))
  
      ret = [
          h for h, full_h in header_list if match_regex.match(full_h)
      ]
      print("Located %s headers matching given pattern." % len(ret))
  
      return ret
  
file_path: turicreate/scripts/fix_headers.py
imports: import os
  import re
  import sys
  from os.path import join, split, normpath, exists
  import subprocess
  import argparse
  from collections import defaultdict
label_desc: Use image node_id 7 for calling a global function with example usage: all_headers_matching(match_regex) and returns: ret, header_list