fork download
  1. import re
  2.  
  3. entities = ['blab', 'r1', 'zss']
  4. sentences = ['this r1 is about zsse', 'this [r1] is about [zss]e']
  5. new_sentences = []
  6.  
  7. for s in sentences:
  8. for e in entities:
  9. if re.search(r"\[%s\]" % e, s):
  10. pass
  11. else:
  12. s=s.replace(e,'['+e+']')
  13. new_sentences.append(s)
  14.  
  15. print(new_sentences)
Success #stdin #stdout 0.02s 44680KB
stdin
Standard input is empty
stdout
['this [r1] is about [zss]e', 'this [r1] is about [zss]e']