Step 14
Now, you would join the elements of the segment (part
) with the pipe character (|
).
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)
.
for square_no, part in enumerate([line[:3], line[3:6], line[6:]], start=1):
for item in part (|):
part.join(I)
str(part)
what do I have to do here?
MOD EDIT: Link to the step:
https://www.freecodecamp.org/learn/scientific-computing-with-python/learn-classes-and-objects-by-building-a-sudoku-solver/step-14
I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').
For that, first, use a for
loop for item in part
to access all elements.
This instruction should really say to use a list comprehension, not a loop.
use the join()
method on the |
character
This is the Pipe character |
not a capital i
. It’s above the Enter key with the backslash. You are using join on part
instead of pipe |
convert each element to a string using str(item)
It gives you the correct answer here, str(item)
but you have written str(part)
- Start with calling
join()
on the pipe character |
- In the brackets of
join()
use a list comprehension for item in part
- use the list comprehension to convert each item to a string using
str(item)