title: How to align numbers by decimal position?
body: <p>My table: </p>
  
  <pre><code>  2       4,5   100    400
    3        20    10    100
  4,2    10.000   500    600
  9,2  10.024,5   610  1.100
  
  mylist = [['2', '4,5', '100', '400'], ['3', '20', '10', '100'], ['4,2', '10.000', '500', '600'], ['9,2', '10.024,5', '610', '1.100']]
  </code></pre>
  
  <p>How can I align the numbers like this:</p>
  
  <pre><code>2         4,5  100    400
  3        20     10    100
  4,2  10.000    500    600
  9,2  10.024,5  610  1.100
  </code></pre>
  
  <p>What I did:</p>
  
  <pre><code>for i in range(0, len(mylist)):
      '{:&gt;10} {:&gt;10} {:&gt;10} {:&gt;10}'.format(mylist[i][0], mylist[i][1], mylist[i][2], mylist[i][3])
  </code></pre>
  
  <p>This gives above results as in the 1st table but the decimals are not aligned.</p>
  
  <p><strong>Update</strong><br>
  I adapted the solution of Francisco to the length of the elements in whatever list.</p>
  
  <pre><code>mylist = [['1300', '300', '300'], ['2300,5', '300,5', '300,5'], ['3600000000000', '6000000', '6000000'], ['4200,2345', '200,2345', '200,2345'], ['5301', '301', '301'], ['6200', '200', '200'], ['7300', '300', '300000000'], ['8300,5', '300,500000', '300,5'], ['960000', '600', '6000'], ['10200,2345', '200999,2345', '200,2345'], ['11301', '301', '301'], ['12200', '200', '200'], ['13300', '300', '300'], ['14300,5', '300,5', '300,5']]
  
  column2row = zip(*mylist)
  maxbefore = []
  maxafter = []
  for m in column2row:
      maxlengthbefore = 0
      maxlengthafter  = 0
      for e in m:
          if ',' in e:
             lengthbefore = len(str(e).split(",")[0])
             if lengthbefore &gt; maxlengthbefore:
                maxlengthbefore = lengthbefore
             lengthafter  = len(str(e).split(",")[1])
             if lengthafter &gt; maxlengthafter:
                maxlengthafter = lengthafter
          else:
             lengthbefore = len(str(e))
             if lengthbefore &gt; maxlengthbefore:
                maxlengthbefore = lengthbefore
      maxbefore.append(maxlengthbefore)
      maxafter.append(maxlengthafter + 1)
  
  for m in mylist:
      r = 0
      for e in m:
          if ',' in e:
              print(e.rjust(int(maxbefore[r]) + len(e) - e.index(',')).ljust(int(maxbefore[r])+int(maxafter[r])), end=' ')
          else:
              print(e.rjust(int(maxbefore[r])).ljust(int(maxbefore[r])+int(maxafter[r])), end=' ')
          r += 1
      print()
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>         1300          300              300      
           2300,5        300,5            300,5    
  3600000000000      6000000          6000000      
           4200,2345     200,2345         200,2345 
           5301          301              301      
           6200          200              200      
           7300          300        300000000      
           8300,5        300,500000       300,5    
         960000          600             6000      
          10200,2345  200999,2345         200,2345 
          11301          301              301      
          12200          200              200      
          13300          300              300      
          14300,5        300,5            300,5
  </code></pre>