input = (Columbia and (India or Singapore) and Malaysia)
output = [Columbia, India, Singapore, Malaysia]
基本上忽略python关键字和括号
我尝试了下面的代码,但仍然无法消除大括号
import keyword
my_str=input()
l1=list(my_str.split(" "))
l2=[x for x in l1 if not keyword.iskeyword((x.lower()))]
print(l2)
re.sub(r'[\(\)\[\]{}]','',my_str)
这将用空字符串替换所有类型的大括号(从而删除它们)
试试这个:
输出:
没有正则表达式:
相关问题 更多 >
编程相关推荐