To teraz właściwy problem:
def splitString_In(formula, separators, i): #["<=", "=="]
formula = formula.split(separators[i - 1])
if i > 1:
for idx in range(len(formula)):
return splitString_In(formula[idx], separators, i - 1)
return formula
def splitString(formula, separators):
if isinstance(formula, str) and len(separators) > 0:
return splitString_In(formula, separators, len(separators))
print(splitString("1 + 2 < 4 = 1 + 3", ["<", "="])) #zwraca ['1 + 2 ', ' 4 '], zamiast [['1 + 2 '], [[' 4 '], [' 1 + 3']]]
Chcę opakować wzór w listy, rozdzielając każdy string przez operator porównania. Niestety nie działa. Mam wersję iteracyjną, która działa, ale dodawanie kolejnego operatora przyprawia mnie o zawrót głowy. Proszę o pomoc.
Tu wersja iteracyjna:
qcs = qcs.split("==")
for x1 in range(len(qcs)):
qcs[x1] = qcs[x1].split("<=")
for x2 in range(len(qcs[x1])):
qcs[x1][x2] = qcs[x1][x2].split(">=")
for x3 in range(len(qcs[x1][x2])):
qcs[x1][x2][x3] = qcs[x1][x2][x3].split("!=")
for x4 in range(len(qcs[x1][x2][x3])):
qcs[x1][x2][x3][x4] = qcs[x1][x2][x3][x4].split("=")
for x5 in range(len(qcs[x1][x2][x3][x4])):
qcs[x1][x2][x3][x4][x5] = qcs[x1][x2][x3][x4][x5].split("<")
for x6 in range(len(qcs[x1][x2][x3][x4][x5])):
qcs[x1][x2][x3][x4][x5][x6] = qcs[x1][x2][x3][x4][x5][x6].split(">")
Proszę o pomoc. Dzięki!