Learn Classes and Objects by Building a Sudoku Solver - Step 14

Tell us what’s happening:

I don’t understand what I should do now… My intuition tells me that I should store the value of the joined item somewhere, but the problem doesn’t say where. Also, what does it mean that I should turn each item into a string after joining them into one line?

Your code so far

class Board:
    def __init__(self, board):
        self.board = board

    def __str__(self):
        upper_lines = f'\n╔═══{"╤═══"*2}{"╦═══"}{"╤═══"*2}{"╦═══"}{"╤═══"*2}╗\n'
        middle_lines = f'╟───{"┼───"*2}{"╫───"}{"┼───"*2}{"╫───"}{"┼───"*2}╢\n'
        lower_lines = f'╚═══{"╧═══"*2}{"╩═══"}{"╧═══"*2}{"╩═══"}{"╧═══"*2}╝\n'
        board_string = upper_lines

        for index, line in enumerate(self.board):
            row_list = []

/* User Editable Region */

            for square_no, part in enumerate([line[:3], line[3:6], line[6:]], start=1):
                for item in part:
                    '|'.join(item)

/* User Editable Region */

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Learn Classes and Objects by Building a Sudoku Solver - Step 14

Hello Erikhenriqueal,

You’re now using a normal for loop, but this is kind of a throw back to the List Comprehensions we learned earlier.

So instead of a normal for loop, keep the '|'.join() but add the rest of the question inside. So you need to turn item in to a string, then loop using the loop they mentioned for item in part. I found this also very challanging so let me know how far you got and I’ll help you further if you didn’t get it after this.

1 Like

Hey HungryBee, thanks for your atention!

You helped me see an error in my code, but I still haven’t found the solution. I thought that, instead of iterating into part list, using [str(item) for item in part] would work, because it worked on my localhost, but it’s not working on the project.

Could you help me find out where am I going wrong?

You’re getting there, can you post the full code so I can see what exactly you did?

Here’s the full code:

class Board:
    def __init__(self, board):
        self.board = board

    def __str__(self):
        upper_lines = f'\n╔═══{"╤═══"*2}{"╦═══"}{"╤═══"*2}{"╦═══"}{"╤═══"*2}╗\n'
        middle_lines = f'╟───{"┼───"*2}{"╫───"}{"┼───"*2}{"╫───"}{"┼───"*2}╢\n'
        lower_lines = f'╚═══{"╧═══"*2}{"╩═══"}{"╧═══"*2}{"╩═══"}{"╧═══"*2}╝\n'
        board_string = upper_lines

        for index, line in enumerate(self.board):
            row_list = []

            # Actual Problem
            for square_no, part in enumerate([line[:3], line[3:6], line[6:]], start=1):
                '|'.join([ str(item) for item in part ])
            # Problem End

Just remove the [ and ] now and you got it! :blush:

1 Like

Oh, wait… I didn’t know that it was possible… I thought that creating a new list was needed to use the List Comprehension method. But ok, you got it, it works!

Thank you so much, and happy new year!

1 Like