Eenoku Eenoku - 4 months ago 11
Python Question

Python autoformat string containing strings of fixed length

Let's say I have an arbitrary number of strings of the same length, e.g.:


And I need to format them into "one line grid" (separated with spaces) with fixed length. So, I'd like to do something like this:

>>'{some expression, 15, left}'.format(['01','02','03'])
'01 02 03 '

>>'{some expression, 15, right}'.format(['01','02','03'])
' 01 02 03'

Is it possible to do it like this just with format or in some other elegant way?

I want to use Python 3.

list = ['01','02','03']
list1=', '.join(list)
list_right='{:>15}'.format(list1)   # right 
list_left='{:<15}'.format(list1)    #left