How to print each column of strings separately in python?

Question:

I have used python to print a string "aaaaabbbbbccccc" into 5 separate columns of characters. I have not used an array to do this.

a a a a a
b b b b b 
c c c c c 

Now I want to print each column separately from each other, so for example print only the first column and then do this for all other columns:

a
b
c

To print the characters in 5 different columns I have used:

var="aaaaabbbbbccccc" 
count=0 
for char in var:   
 if count<4:
  print(char, end="  ")
  count=count+1   
 else:
  count=0
  print(char)
Asked By: Auras

||

Answers:

Unsure what the aim of this code is, but I have tried to stick to your existing code structure:

var = 'aaaaabbbbbccccc'
cnt = 0
col_to_print = 4 # change this to print a different col.
for char in var:
    if cnt == col_to_print:
        print(char)
    if cnt<4:
        cnt +=1
    else:
        cnt = 0

output:

a
b
c
Answered By: Jacob Kearney
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.