def add_parents(paths):
 all_paths = set()
 for path in paths:
  while (u'//' in path):
   path = path.replace(u'//', u'/')
  all_paths.add(path)
  if (u'/' in path):
   parent_dir = dirname(path)
   while parent_dir:
    all_paths.add(parent_dir)
    parent_dir = dirname(parent_dir)
 return all_paths

def add_parents ( paths ) : all_paths = set ( ) for path in paths : while ( u'//' in path ) : path = path . replace ( u'//' , u'/' ) all_paths . add ( path ) if ( u'/' in path ) : parent_dir = dirname ( path ) while parent_dir : all_paths . add ( parent_dir ) parent_dir = dirname ( parent_dir ) return all_paths
iterate over each item in the set and add its parent directories .