Formatting a list of text into columns

前端 未结 8 1030
我在风中等你
我在风中等你 2021-02-07 08:34

I\'m trying to output a list of string values into a 2 column format. The standard way of making a list of strings into \"normal text\" is by using the string.join

8条回答
  •  你的背包
    2021-02-07 09:27

    It's long-winded, so I'll break it into two parts.

    def columns( skills_defs, cols=2 ):
        pairs = [ "\t".join(skills_defs[i:i+cols]) for i in range(0,len(skills_defs),cols) ]
        return "\n".join( pairs )
    

    It can, obviously, be done as a single loooong statement.

    This works for an odd number of skills, also.

提交回复
热议问题