Loop print through two lists to get two columns with fixed(custom set) space between the first letter of each element of each list

for-loop, list, loops, pretty-print, python

Solution

Easily done with the string formatting,

column1 = ["soft","pregnant","tall"]
column2 = ["skin","woman", "man"]

for c1, c2 in zip(column1, column2):
    print "%-9s %s" % (c1, c2)

Or you can use `str.ljust`, which is tidier if you want to have the padding be based on a variable:

padding = 9
for c1, c2 in zip(column1, column2):
    print "%s %s" % (c1.ljust(padding), c2)

(note: padding is `9` instead of `10` because of the hard-coded space between the words)

Problem

Suppose I have these two lists: ``` column1 = ["soft","pregnant","tall"] column2 = ["skin","woman", "man"] ``` How do I loop print through these two lists while using a custom, fixed space(say 10, as in example) starting from the first letter of each element of the first list up to the first letter of each element of the second list? Example output of a set spacing of 10: ``` soft skin pregnant woman tall man ```

Original source

Related problems