Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 将单行循环转换为多行循环_Python 3.x_Loops - Fatal编程技术网

Python 3.x 将单行循环转换为多行循环

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:

在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)

感谢您的帮助

您可以为嵌套的单行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)

你为什么有麻烦?你试过什么吗?还有,你看到了吗?我不会问我是否试过。顺便说一句,谢谢。