История изменений
Исправление legolegs, (текущая версия) :
Мне кажется, что если условий (не считая ошибок) больше трёх,то пора бы задуматься о выводе логики в таблицу.
def f(x):
REQ_Y=True
REQ_Z=True
conds = (
(cond1, None, None, res1),
(cond2, REQ_Y, None, res2),
(cond3, REQ_Y, None, res3),
(cond4, REQ_Y, REQ_Z, res4),
(cond5, REQ_Y, REQ_Z, res5),
)
y=None
z=None
for cond,ry,rz,res in conds:
if ry and not y: y=process1(x)
if rz and not z: z=process2(x,y)
if cond(x=x,y=y,z=z):
return res
return 'nope'
PS я не настоящий питонист
Исходная версия legolegs, :
Мне кажется, что если условий (не считая ошибок) больше трёх,то пора бы задуматься о выводе логики в таблицу.
def f(x):
REQ_Y=True
REQ_Z=True
conds = (
(cond1, None, None, res1),
(cond2, REQ_Y, None, res2),
(cond3, REQ_Y, None, res3),
(cond4, REQ_Y, REQ_Z, res4),
(cond5, REQ_Y, REQ_Z, res5),
)
y=None
z=None
for cond,ry,rz,res in conds:
if ry and not y: y=process1(x)
if rz and not z: z=process2(x,y)
if cond(x=x,y=y,z=z):
return res
return 'nope'