[Python] Are There Better Ways to Track Success/Failure in Python Loops?

Discussão em 'Python' iniciado por Stack, Agosto 19, 2025.

  1. Stack

    Stack Membro Participativo

    I'm creating a wordsearch generator that takes a list of words and outputs a 10x10 grid (2D array) of letters. This is roughly how it works:

    1. loop over words
    use boolean word_good to track whether the words could be added to the grid.
    2. for each word, loop over 3 possible directions
    use boolean direction_good to check if a dimension was suitable for this word. if false, it continues searching. if true, it makes word_good TRUE.
    3. for each dimension, check all positions, and see if the characters can be added.
    use boolean position_good to check if one is available. if false, it continues searching. if true, it makes direction_good TRUE.


    I feel like there should be a more efficient (or at least reader-friendly) way of tracking these success/failure cases. Any ideas?

    Not sure if I should post my code because it contains a lot of clutter. Please ask for clarification if needed.

    Edit: This is for a competition, and submissions that are clearer and better-explained gain more points, hence why I want to improve this detail.

    Continue reading...

Compartilhe esta Página