我正在解析等式中的數字。從我的代碼沒有什麼問題。 它不能識別等式中的數字1,因爲通常在等式中,數字1被跳過。從x,y,z等式解析數字
def equationSystem(e):
a = []
for s in e:
a.append(re.findall("[-]?\d+[\.]?\d*[eE]?[-+]?\d*", s))
print a[0]
例如
equation = ["-x+y+z=0", "x-3y-2z=5", "5x+y+4z=3"]
預期輸出
[[-1, 1, 1, 0], [1, -1, -2, 5], [5, 1, 4, 3]]
,但實際產量
[[0], [-2, 5], [5,1,4,3]]
你能幫助我提高了正則表達式?
您可以在預處理階段添加缺少的1s –