Python 3.x Python中逻辑运算符与成员运算符的组合
我无法将逻辑运算符“”和“”与成员运算符“”正确组合。在这里,我想要一个没有空字符串和只有标点符号的干净列表Python 3.x Python中逻辑运算符与成员运算符的组合,python-3.x,Python 3.x,我无法将逻辑运算符“”和“”与成员运算符“”正确组合。在这里,我想要一个没有空字符串和只有标点符号的干净列表 val_list = [['infertility fear', 'teenage pregnancy', 'public health', 'health science', 'parenthood'], ['mass health checkups', 'personality traits', '-', '']] 预期产量 ['infertility fear', 'teenag
val_list = [['infertility fear', 'teenage pregnancy', 'public health', 'health science', 'parenthood'], ['mass health checkups', 'personality traits', '-', '']]
预期产量
['infertility fear', 'teenage pregnancy', 'public health', 'health science', 'parenthood', 'mass health checkups', 'personality traits']
错误
文件“”,第11行
flat_val_list=[item.strip()表示子列表中的子列表,如果(item!='')而不是(list(string.标点符号)),则表示子列表中的项
^
SyntaxError:无效语法
您需要说项目不在…
。在这里:
flat_val_list=[item.strip()表示子列表中的子列表,如果(item!='')表示子列表中的项,而不在(list(string.标点符号))]
和项目不在…
…!?
flat_val_list = [item.strip() for sublist in val_list for item in sublist if (item != '') and not in (list(string.punctuation))]
File "<ipython-input-40-3f1a39d4169d>", line 11
flat_val_list = [item.strip() for sublist in val_list for item in sublist if (item != '') and not in (list(string.punctuation))]
^
SyntaxError: invalid syntax