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

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

    This will work:

    n = m = 0
    while m < len(l):
        m = m+5
        print("".join(l[n:m]))
        n = m
    

    But I believe there is a more pythonic way to accomplish the task.

提交回复
热议问题