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

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

    I think the most cleaner way to write this would be

    list=['a','b','c','d','e','f','g','h', 'i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
    
    for i in range(0, len(list), 5):
        print(*list[i:i+5], sep='')
    

提交回复
热议问题