def pseudonymize_text(replacements, text): """ Create new text with pseudos in place of NER """ index = 0 pseudonymized_text = '' for key in sorted(replacements.keys()): chunk = text[index:key[0]] # print(text[key[0]:key[1]]) pseudonymized_text += chunk pseudonymized_text += replacements[key] index = key[1] pseudonymized_text += text[index:] return pseudonymized_text