Print 5 items in a row on separate lines for a list?

前端 未结 11 1205
耶瑟儿~
耶瑟儿~ 2021-02-07 19:15

I have a list of unknown number of items, let\'s say 26. let\'s say

list=[\'a\',\'b\',\'c\',\'d\',\'e\',\'f\',\'g\',\'h\',
\'i\',\'j\',\'k\',\'l\',\'m\',\'n\',\'         


        
11条回答
  •  我寻月下人不归
    2021-02-07 19:42

    for i, a in enumerate(A):
        print a, 
        if i % 5 == 4: 
            print "\n"
    

    Another alternative, the comma after the print means there is no newline character

提交回复
热议问题