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

前端 未结 11 1154
耶瑟儿~
耶瑟儿~ 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:32

    start = 0
    for item in list:
        if start < 4:
            thefile.write("%s" % item)
            start = start + 1
        else:                             #once the program wrote 4 items, write the 5th item and two linebreaks
            thefile.write("%s\n\n" % item)
            start = 0
    

提交回复
热议问题