s = "((a*b>0) * (e>500)) * (abs(j)>2.0) * (n>1)"
s = ''.join(s.split())
s = re.split(r'([\)]+[\*\+\-/\^]+[\(])', s)
res = []
for x in s:
x = re.sub(r'(^[\(\)\*\+\-\/]+)', '', x)
x = re.sub(r'([\(\)]+$)', '', x)
if len(x) > 0: res.append(x)
print(res)
您只需使用
split()
函数:注意倍增号周围的空格。这假设您的字符串与您所说的完全相同。在
您可以使用regex:
相关问题 更多 >
编程相关推荐