fork download
  1. from re import sub
  2.  
  3.  
  4. def link_conjunctions_with_words(text):
  5. return sub(r'\s+([\wА-Яа-я]{1,2})\s+', r' \1' + '\u00A0', text)
  6.  
  7.  
  8. def link_conjunctions_with_words2(text):
  9. return sub(r'\s+([\wА-Яа-я]{1,2})\s+', ' \\1\u00A0', text)
  10.  
  11.  
  12. def link_conjunctions_with_words3(text):
  13. return sub(r'\s+([\wА-Яа-я]{1,2})\s+', ' \\1\u00A0', text)
  14.  
  15.  
  16. text = "кофе с молоком"
  17.  
  18. print(link_conjunctions_with_words(text))
  19.  
  20. print(link_conjunctions_with_words2(text))
  21.  
  22. print(link_conjunctions_with_words3(text))
Success #stdin #stdout 0.04s 9960KB
stdin
Standard input is empty
stdout
кофе с молоком
кофе с молоком
кофе с молоком