How to print a list more nicely?

前端 未结 22 1290
北荒
北荒 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 09:53

    Simple:

    l = ['exiv2-devel', 'mingw-libs', 'tcltk-demos', 'fcgi', 'netcdf', 
        'pdcurses-devel',     'msvcrt', 'gdal-grass', 'iconv', 'qgis-devel', 
        'qgis1.1', 'php_mapscript']
    
    if len(l) % 2 != 0:
        l.append(" ")
    
    split = len(l)/2
    l1 = l[0:split]
    l2 = l[split:]
    for key, value in zip(l1,l2):
        print '%-20s %s' % (key, value)         #python <2.6
        print "{0:<20s} {1}".format(key, value) #python 2.6+
    

提交回复
热议问题