将单行循环转换为多行循环Python

时间:2018-03-29 05:13:30

标签: 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:
            out_str = out_str+char
    out_list.append(out_str)

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

您可以尝试使用嵌套的一行代码片段进行循环

(daylight saving)