How to print a list more nicely?

前端 未结 22 1291
北荒
北荒 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:04

    Although not designed for it, the standard-library module cmd has a utility for printing a list of strings in multiple columns

    import cmd
    cli = cmd.Cmd()
    cli.columnize(foolist, displaywidth=80)
    

    You even then have the option of specifying the output location, with cmd.Cmd(stdout=my_stream)

提交回复
热议问题