How to print a list more nicely?

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

    If the data is in the format you have provided, it is a little more work

    
    >>> d = ['exiv2-devel', 'mingw-libs', 'tcltk-demos', 'fcgi', 'netcdf', 
    ...     'pdcurses-devel',     'msvcrt', 'gdal-grass', 'iconv', 'qgis-devel', 
    ...     'qgis1.1', 'php_mapscript']
    >>> print "\n".join("%-20s %s"%(d[i],d[i+len(d)/2]) for i in range(len(d)/2))
    exiv2-devel          msvcrt
    mingw-libs           gdal-grass
    tcltk-demos          iconv
    fcgi                 qgis-devel
    netcdf               qgis1.1
    pdcurses-devel       php_mapscript
    

提交回复
热议问题