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

Tell us what’s happening:

Stuck on this problem for 4 hrs. Need serious help!
I keep trying to convert the elements to string but it just doesn’t work!

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(part)
                    item = str(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/123.0.0.0 Safari/537.36

Challenge Information:

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

The instructions ask for a for loop, but it’s wrong, you need to write a comprehension.

Do you know the comprehension syntax? It’s like a for loop only backwards:

for this in that:
    print(this)

#as a comprehension:
print(this) for this in that 
  1. Call the join() method on the string “|”.
  2. To the join method you pass a generator comprehension
  3. the comprehension will do str(item) for each element of part

This is all 1 line. You can use this syntax:

"string".join(str(this) for this in that)