I've been looking into how to print data into columns. I haven't been able to find an elegant way to do this with either a dictionary (keys) or a list (taking keys from dictionary into list).
Ive looked into iterating over each key and printing that, but that doesn't work as you can't use mapping. I've tried using a list and printing each item from the list using string formatting
but as you'd imagine I get back each character with a space from each list item, I can't seem to use .join
. The closest I have been able to get to what I'd like is the answer from Aaron Digulla
here. However this does not print the list items in alphabetical order. I cant believe there is'nt a simple elegant way to do this?
Method from answer discussed above
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 "{0:<20s} {1}".format(key, value)