I am having trouble printing out a list of items with n items per line. Here is my current code.
def printList(lst, lineCount): # given a list of items, print it out in # lineCount items per line. count=0 strList= '[ ' for element in lst: strList = strList+ str(element) + ' ' count= count +1 if count%lineCount==0: strList = strList + '\n' strList=strList+ ' ]' return strList
Right now, the if statement is supposed to check if the list reaches the lineCount element in list. Then. I add the '\n' New line escape sequence to the list.
But right now the list is only printing the '\n' mark. What happened?