I have a list lst
of entries = namedtuple( 'Entry', ['title', 'x', 'y', 'val'])
where each element elm
of the lst
is of <class 'generator'>
.
I have a method which prints the elements of that list like so:
def print_elements_lst(lst_to_print):
return "\n".join("%s %s %s %s" % elm for elm in lst_to_print)
My issue is that I am trying to add padding between the 1st and 2nd strings (i.e. between the 'title'
and 'x'
) so that there will be a consistent number of empty spaces between them.
From here, I compute the desired padding like so:
pad = max(len(token) for elm in lst_to_print) + 2
But I am having problems on how to implement this in the formatted output along with the namedtuple
values.
Any suggestions?