Python 3.x 将单行循环转换为多行循环
在python中将这一单行循环转换为多行代码时,我遇到了麻烦Python 3.x 将单行循环转换为多行循环,python-3.x,loops,Python 3.x,Loops,在python中将这一单行循环转换为多行代码时,我遇到了麻烦 text_data = [''.join(char for char in sent if char not in punct) for sent in text_data] 提前谢谢 更新 解决了 out_list = [] for sent in test_data: out_str = '' for char in sent: if char not in punct:
text_data = [''.join(char for char in sent if char not in punct) for sent in text_data]
提前谢谢
更新
解决了
out_list = []
for sent in test_data:
out_str = ''
for char in sent:
if char not in punct:
out_str = out_str+char
out_list.append(out_str)
感谢您的帮助您可以为嵌套的单行for循环尝试以下代码段
out_list = []
for sent in text_data:
out_str = ''
for char in sent:
if char not in punct:
out_str.join(char)
out_list.append(out_str)
你为什么有麻烦?你试过什么吗?还有,你看到了吗?我不会问我是否试过。顺便说一句,谢谢。