Skip to content
Advertisement

Removing initial whitespace plus the last empty new line line using python

I am trying to implement a code that prints an 8 by 8 matrix (0 to 63). It should however remove the initial tab spaces and the last empty line. My code is below :

JavaScript

The image Below is also the desired output

enter image description here

I have tried the dedent function but it fails to remove the last line as well

Advertisement

Answer

Basically all you are looking for is whenever you go to a new line, the initial space is not printed, since every newline is a j, you will need to add:

JavaScript

It should work. Will look like this now:

JavaScript

Let me know if it has any problems.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement