Форум сайта python.su
2
Приветствую.
Имеем такой шаблон:
<Ol>
<li>[key_other] [key_other]</li>
<li>[key_other] [key_other]</li>
<li>[key_other] [key_other]</li>
</Ol>
text.replace('[key_other]', random.choice(my_list))
text = re.sub(r'[key_other]', random.choice(my_list), text)
Отредактировано bs0d (Дек. 7, 2014 16:28:25)
Офлайн
103
как вариант
for i in range(text.count("[key_other]")): text = text.replace('[key_other]', random.choice(my_list), 1)
Офлайн