title: How to print lists (of different length containing colored characters) as columns in Python without using imports?
body: <p>I'm trying to print out the following triangle using columns instead of rows:</p>
  <pre><code>def r(x):
      return '\x1b[6;31;50m{}\x1b[0m'.format(x)
  
  
  def g(x):
      return '\x1b[1;32;50m{}\x1b[0m'.format(x)
  
  
  def rb(x):
      return '\x1b[5;31;51m{}\x1b[0m'.format(x)
  
  
  print(f'1    10    {rb(208)}    {r(1234)}')
  print(5*' ', f'{g(&quot;1&quot;)}     {g(&quot;1&quot;)}{r(&quot;0&quot;)}     {g(208)}')
  print(12*' ', f'1      {r(&quot;1&quot;)}0')
  print(20*' ', f'{r(1)} ')
  </code></pre>
  <p>If I want to add a column as the code is now, I have to add spaces and one element to the end of each print statement. That's not a big deal for this example, but I'm not looking forward to column 50 or 100. I thought I'd just write each column as a separate list instead and then combine them into a list of lists and loop through it, but I got stuck.</p>
  <p>Printing one list as a column while keeping the alignment was pretty straight forward, but I don't know how to handle the lists being of different lengths (the spacing is fine, but the fact that all lists will have different lengths got me).</p>
  <pre><code>col = ['32Σ21', '1234', '208', '10', '1']
  col5color = [&quot;33&quot;+r(&quot;Σ2&quot;)+g(&quot;1&quot;), g(&quot;12&quot;)+r(&quot;34&quot;), r(&quot;2&quot;)+g(&quot;08&quot;), rb(&quot;10&quot;), r(&quot;1&quot;)]
  maxlen = len(col[0])
  for i in range(len(col)):
      print((maxlen - len(col[i]))*' ' + col5color[i])
  </code></pre>
  <p>The lists for the first four columns:</p>
  <pre><code>col4color = [r(&quot;1234&quot;), g(&quot;208&quot;), r(&quot;1&quot;) + &quot;0&quot;, r(&quot;1&quot;)]
  col3color = [rb(&quot;208&quot;), g(&quot;1&quot;) + r(&quot;0&quot;), &quot;1&quot;]
  col2color = [&quot;10&quot;, g(&quot;1&quot;)]
  col1color = [&quot;1&quot;]
  </code></pre>
  <p>To clarify: I can't change the layout (flip rows/columns), I can't use imports and I have to hardcode it. That's why I would like to tidy it up and minimize the risk of errors. If  I could just deal with the different lengths I would only have to add one element at the first index of &quot;col&quot;, copy and paste &quot;col&quot;, change the name to &quot;colncolor&quot; and then change the colors. I don't know much about the next column beforehand, but I know that the new element will have at least as many characters as the element in the previous column, so I never have to change &quot;maxlen&quot;.</p>