def invert_docs_link_map(docs_links):
 files_to_docs = defaultdict(list)
 for (doc, files) in docs_links.iteritems():
  for file in files:
   files_to_docs[file].append(doc)
   files_to_docs[file] = list(set(files_to_docs[file]))
 return files_to_docs

def invert_docs_link_map ( docs_links ) : files_to_docs = defaultdict ( list ) for ( doc , files ) in docs_links . iteritems ( ) : for file in files : files_to_docs [ file ] . append ( doc ) files_to_docs [ file ] = list ( set ( files_to_docs [ file ] ) ) return files_to_docs
the docs links map is in this format: "doc_path": [ "file_path" .