"ZPXP", "ZMXP", "ZPXM", "ZMXM", "ZPYP", "ZMYP", "ZPYM", "ZMYM", "XPZP", "XMXZ", "XPZM", "XMXZ", "XPYP", "XMYP", "XPYM", "XMYM", "YPXP", "YMXP", "YPXM", "YMXM", "YPZP", "YMZP", "YPZM", "YMZM"
existe alguna manera de estructurar el flujo de los condicionales para mejorar el performance?
por ejemplo, si lo estructuro de esta manera, consigo que el numero de pasos sea menor?:
Código Python:
Ver original
if direction[0] == "Z": if direction[:2] == "ZP": if direction == "ZPXM": pass elif direction == "ZPYP": pass elif direction == "ZPYM": pass elif direction == "ZPXP": pass else: pass elif direction[:2] == "ZM": if direction == "ZMXM": pass elif direction == "ZMYP": pass elif direction == "ZMYM": pass elif direction == "ZMXP": pass else: pass else: pass elif direction[0] == "Y": if direction[:2] == "YP": if direction == "YPZM": pass elif direction == "YPXM": pass elif direction == "YPZP": pass elif direction == "YPXP": pass else: pass elif direction[:2] == "YM": if direction == "YMZM": pass elif direction == "YMXM": pass elif direction == "YMZP": pass elif direction == "YMXP": pass else: pass else: pass elif direction[0] == "X": if direction[:2] == "XP": if direction == "XPYM": pass elif direction == "XPZM": pass elif direction == "XPYP": pass elif direction == "XPZP": pass else: pass elif direction[:2] == "XM": if direction == "XMZM": pass elif direction == "XMYM": pass elif direction == "XMZP": pass elif direction == "XMYP": pass else: pass else: pass else: pass
si no estoy equivocado para este caso el numero mínimo de pasos que se pueden ejecutar es 3 (si "direction" == "ZPXM") y el numero máximo seria 9 (si "direction" == "XMYP")
otra forma de estructurarlo seria simplemente probar para todos y cada uno de los pasos:
Código Python:
Ver original
if direction == "ZPXM": pass elif direction == "ZPYP": pass elif direction == "ZPYM": pass elif direction == "ZPXP": pass elif direction == "ZMXM": pass elif direction == "ZMYP": pass elif direction == "ZMYM": pass elif direction == "ZMXP": pass elif direction == "YPZM": pass elif direction == "YPXM": pass elif direction == "YPZP": pass elif direction == "YPXP": pass elif direction == "YMZM": pass elif direction == "YMXM": pass elif direction == "YMZP": pass elif direction == "YMXP": pass elif direction == "XPYM": pass elif direction == "XPZM": pass elif direction == "XPYP": pass elif direction == "XPZP": pass elif direction == "XMZM": pass elif direction == "XMYM": pass elif direction == "XMZP": pass elif direction == "XMYP": pass else: pass
para este caso el minimo seria 1, y el maximo seria 24..
bueno la pregunta es, estructurar el codigo de la primera forma seria "mejor" que de la segunda?, existe alguna mejor manera de estructurar esto?