title: Automate the Boring Stuff Chapter 6 Table Printer Almost Done
body: <p>In this section, they want us to create this table:</p>
  
  <pre><code>    apples Alice dogs
       oranges Bob cats
   cherries Carol moose
     banana David goose
  </code></pre>
  
  <p>It must be justified to the right, and the input is tableData. Here's my code:</p>
  
  <pre><code>tableData=[['apples', 'oranges', 'cherries', 'banana'],
          ['Alice', 'Bob', 'Carol', 'David'],
          ['dogs', 'cats', 'moose', 'goose']]
  listlens=[]
  tour=0
  lists={}
  for m in tableData:
      total=0
      tour+=1
      for n in m:
          total+=len(n)
          lists["list:",tour]=total
      print("list",tour,total)    
  
  itemcount=list(lists.values())
  sortedlen=(sorted(itemcount,reverse=True))
  longest=sortedlen[0]
  
  #print (lists['list:', 1])
  #print (longest)
  
  
  for m in range(len(tableData[0])):
      for n in range(len(tableData)):
          print (tableData[n][m],end=" ")
          n+=1
      print ("".rjust(lists['list:', 1],"-"))
      m+=1
  </code></pre>
  
  <p>I'm almost done except for one thing, I can't make it right-justified. This output is the closest I came so far.</p>
  
  <pre><code>apples Alice dogs ---------------------------
  oranges Bob cats ---------------------------
  cherries Carol moose ---------------------------
  banana David goose ---------------------------
  </code></pre>
  
  <p>If I put rjust inside the inner for-loop the output is much different:</p>
  
  <pre><code>apples-------------------------- Alice-------------------------- dogs-------------------------- 
  oranges-------------------------- Bob-------------------------- cats-------------------------- 
  cherries-------------------------- Carol-------------------------- moose-------------------------- 
  banana-------------------------- David-------------------------- goose-------------------------- 
  </code></pre>