def fmtcols(mylist, cols):
    maxwidth = max(map(lambda x: len(x), mylist))
justifyList = map(lambda x: x.ljust(maxwidth), mylist)
lines = (' '.join(justifyList[i:i + cols]) for i in range(0, len(
    justifyList), cols))
print('\n'.join(lines))
Formatting a list of text into columns