def Columns(text, cols): text = text.replace(" ", "").replace("\n", "") result = "" rowcount = 0 for char in text: if rowcount == 5: rowcount = 0 result += "\n" result += char + " " rowcount += 1 print result