1

Looking how to get my list such as,

myList = ["1", "2", "3", "4", "5", "6", "8", "9"]

into a tabular format like,

1    2    3
4    5    6
7    8    9

I would prefer using a loop to automate it so that it picks the first 3 items from the list and then moves the next 3 onto the next row and so on. I found similar problems but couldn't find out how to implement it into my program, I am just a beginner in python.

Thanks!

1 Answer 1

1
myList = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]

Below, we enumerate myList, and we print a newline every 3 characters.

for j, i in enumerate(myList):
    if j%3==0:
        print('\n')
    print(i, end= " ")

Output:

1 2 3 

4 5 6 

7 8 9
Sign up to request clarification or add additional context in comments.

1 Comment

The answer was super helpful, I am only having problems with formatting now. Say one of the numbers was 3 digits such as '100' instead of single digit '8' how would I get them to all line up?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.