How to print a list more nicely?

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

    The way Aaron has done it can work with more than two colums

    
    >>> l = ['exiv2-devel', 'mingw-libs', 'tcltk-demos', 'fcgi', 'netcdf', 
    ...     'pdcurses-devel',     'msvcrt', 'gdal-grass', 'iconv', 'qgis-devel', 
    ...     'qgis1.1', 'php_mapscript']
    >>> cols = 4
    >>> split=[l[i:i+len(l)/cols] for i in range(0,len(l),len(l)/cols)]
    >>> for row in zip(*split):
    ...  print "".join(str.ljust(i,20) for i in row)
    ... 
    exiv2-devel         fcgi                msvcrt              qgis-devel          
    mingw-libs          netcdf              gdal-grass          qgis1.1             
    tcltk-demos         pdcurses-devel      iconv               php_mapscript       
    

提交回复
热议问题