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

So, I am completelly stucked here. There is another post with this problem but I am still unable to continue… and the thread is closed. Can anyone please help?

My 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):
            '|'.join(for item in part:
                str(item)

/* User Editable Region */

Step 14
https://www.freecodecamp.org/learn/scientific-computing-with-python/learn-classes-and-objects-by-building-a-sudoku-solver/step-14

For that, first, use a for loop for item in part to access all elements.

Then, use the join() method on the | character to join the elements of the segment (part).

After that, convert each element to a string using str(item).

I have also tried this without success:

           '|'.join(str(for item in part:)

as well as…

            '|'.join(for str(item) in part:)

Normally I get stuck several times in each challenge, but so far it is the irst time that other users posts don’t help me find the answer… please heeeelp! :smiley:

Create the for loop first, then work in the body of the for loop.

for this in that:
   do this

Hi there,

Thanks for the answer, and sorry I didn’t get back earlier, I had a crazy busy week at work… and this weekend was time to chill :slight_smile:

I am trying this but it is failing:

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

Upon trying, I get the following hint:
You should call str() on each element in part using a generator expression.
But I do not understand what is that supposed to mean… the more I search the more confused I get cause nothing seems to be similar to this problem…

I have also tried:

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

…as well as the following, based on what I found in stack overflow…

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

…and…

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

This one seems to be a tough one for me… any hints?

Hi there… ok… there was a syntax error but I fixed it and now it worked. Thanks!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.