How to print a list more nicely?

前端 未结 22 1293
北荒
北荒 2020-12-01 09:34

This is similar to How to print a list in Python “nicely”, but I would like to print the list even more nicely -- without the brackets and apostrophes and commas, and even b

22条回答
  •  半阙折子戏
    2020-12-01 10:05

    See formatting-a-list-of-text-into-columns,

    A general solution, handles any number of columns and odd lists. Tab characters separate columns, using generator expressions to save space.

    def fmtcols(mylist, cols):
        lines = ("\t".join(mylist[i:i+cols]) for i in xrange(0,len(mylist),cols))
        return '\n'.join(lines)
    

提交回复
热议问题