-1
ループを開始して2つのコマンドを実行したいが、最後のコマンドだけが実行される。両方のコマンドを実行するには何が必要ですか?ループ内の2つのコマンド
import re
import string
from string import punctuation
doc_a = "Brocolli is good to eat. My brother likes to eat good brocolli, but not my mother."
doc_b = "My mother spends a lot of time driving my brother around to baseball practice."
doc_c = "Some health experts suggest that driving may cause increased tension and blood pressure."
doc_d = "I often feel pressure to perform well at school, but my mother never seems to drive my brother to do better."
doc_e = "Health professionals say that brocolli is good for your health."
doc_set = [doc_a, doc_b, doc_c, doc_d, doc_e]
for i in doc_set:
doc_set = re.sub(r'\d+', '', i)
doc_set = "".join(l for l in i if l not in string.punctuation)
print(doc_set)
なぜあなたはdoc_set' 'に' re.sub'結果を代入しますか? 're.sub'はリストの一つの要素だけを変更しています。 –
あなたは最初の結果を上書きします – eri
代わりに 'i = re.sub(r '\ d +'、 ''、i)'を実行します。 – L3viathan