code: def remove_directories(list_of_paths):
      
      found_dirs = set('/')
      for path in list_of_paths:
          dirs = path.strip().split('/')
          for i in range(2,len(dirs)):
              found_dirs.add( '/'.join(dirs[:i]) )
  
      paths = [ path for path in list_of_paths if
                (path.strip() not in found_dirs) and path.strip()[-1]!='/' ]
      return paths
docs: Removes non-leafs from a list of directory paths