#!/usr/bin/env python3.5

import re


def text_prepare(text):
    text = text.lower()
    pattern = r"[а-яА-ЯґҐЇїіІєЄ'’]+"
    pattern_exp = re.compile(pattern, re.MULTILINE & re.LOCALE)
    return pattern_exp.findall(text)

def modify_text(text):
    def replace(word, rpl):
        nonlocal text
        re.sub(word, rpl, text)

@@ -29,16 +29,34 @@
 port re%0A
+import build_dict%0A
 %0A%0Adef te
@@ -252,26 +252,87 @@
 fy_text(text
-):
+, word, rpl='BANANA'):%0A    lemmtizer = build_dict.Lemmatizer()%0A
 %0A    def rep
@@ -340,21 +340,16 @@
 ace(word
-, rpl
 ):%0A     
@@ -364,24 +364,29 @@
 cal text
+, rpl
 %0A       
  re.sub(
@@ -377,16 +377,23 @@
 %0A       
+ text =
  re.sub(
@@ -405,12 +405,333 @@
  rpl, text)%0A
+%0A    for current_word in text_prepare(text):%0A        lemma = lemmtizer.lemma(current_word)%0A        if lemma == word:%0A            replace(current_word)%0A%0A    return text%0A%0Aif __name__ == '__main__':%0A    text = '%D0%AF%D0%B1%D0%BB%D1%83%D0%BA%D0%BE %D0%B1%D1%83%D0%BB%D0%BE %D0%B4%D1%83%D0%B6%D0%B5 %D1%81%D0%BC%D0%B0%D1%87%D0%BD%D0%B5. %D0%AF %D0%BB%D1%8E%D0%B1%D0%BB%D1%8E %D1%8F%D0%B1%D0%BB%D1%83%D0%BA%D0%B0.'%0A    print(modify_text(text=text,%0A                      word='%D1%8F%D0%B1%D0%BB%D1%83%D0%BA%D0%BE'))%0A

word replacer