I have a set of numbers that I want to align with a comma:
10 3
200 4000,222 3 1,5
200,21 0,3 2
30000 4,5 1
mylist = [['10', '3', '', ''],
['200', '4000,222', '3', '1,5'],
['200,21', '', '0,3', '2'],
['30000', '4,5', '1', '']]
I want to align this list with a comma:
Expected Result:
mylist = [[' 10 ', ' 3 ', ' ', ' '],
[' 200 ', '4000,222', '3 ', '1,5'],
[' 200,21', ' ', '0,3', '2 '],
['30000 ', ' 4,5 ', '1 ', ' ']]
I tried to rotate the list:
mynewlist = list(zip(*mylist))
and find the longest decimal part in each sublist:
for m in mynewlist:
max([x[::-1].find(',') for x in m]
and use rjust and ljust, but I don’t know how to thin out after the decimal point and rjust before the decimal point, as in one line.
How can I resolve this without using format ()? (I want to combine with ljust and rjust)