code: def AppendIndexDictionaryToFile(uniqueWords, ndxFile, ipFile, useShortFileName='Y'):
      
      if useShortFileName == 'Y':
          f = os.path.basename(ipFile)
      else:
          f = ipFile
      with open(ndxFile, "a", encoding='utf-8', errors='replace') as ndx:
          word_keys = uniqueWords.keys()
          #uniqueWords.sort()
          for word in sorted(word_keys):
              if word != '':
                  line_nums = uniqueWords[word]
                  ndx.write(f + ', ' + word + ', ')
                  for line_num in line_nums:
                      ndx.write(str(line_num))
                  ndx.write('\n')
docs: Save the list of unique words to the master list