[Python] How could this be simplified?

Discussão em 'Python' iniciado por Stack, Fevereiro 4, 2025.

  1. Stack

    Stack Membro Participativo

    it seems really hard to read this part of my code and feels like there is a way to make it shorter so yea, i dont think context of the code matters

    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`


    i dont really have idea of the way how i could improve thos code so i have not tried anything yet

    Continue reading...

Compartilhe esta Página