Wie könnte das vereinfacht werden?
Posted: 04 Feb 2025, 12:20
Es scheint wirklich schwierig, diesen Teil meines Codes zu lesen, und das Gefühl, es gibt eine Möglichkeit, ihn kürzer zu machen. Ja, ich denke nicht
Ich habe wirklich keine Vorstellung davon, wie ich den Code verbessern kann, also habe ich noch nichts ausprobiert.
Code: Select all
if down:
if (
( start[0] , start[1] + index ) in matrix.keys() and
matrix[( start[0] , start[1] + index )] != letter
): return False
elif ( start[0] + index , start[1] ) in matrix.keys(): continue
if (( start[0] , start[1] + index ) in matrix.keys() or
( start[0]-1 , start[1] + index ) in matrix.keys() or
( start[0]+1 , start[1] + index ) in matrix.keys()
): return False
else:
if(
( start[0] + index, start[1] ) in matrix.keys() and
matrix[( start[0] + index, start[1] )] != letter
): return False
elif ( start[0] + index , start[1] ) in matrix.keys(): continue
elif (( start[0] + index , start[1] ) in matrix.keys() or
( start[0] + index , start[1]-1 ) in matrix.keys() or
( start[0] + index , start[1]+1 )in matrix.keys()
): return False`