title: Structure a list of lists as columns and rows for csv/Excel
body: <p>I have this python3 code with a list of lists that I need to structure in a certain way for Excel. Here is what I have:</p>
  
  <pre><code>&gt;&gt;&gt; pprint(avrop_categories[0:3])
  
  [['Name1', ['MainCategory1', 'SubCategory1', ('Item1', 1.0)]],
  
  ['Name2',
  ['MainCategory2', 'Subcategory2', ('Item2', 1.0)],
  ['MainCategory2', 'Subcategory3', ('Item3', 1.0)],
  ['MainCategory2', 'Subcategory4', ('Item4', 1.0)],
  ['MainCategory3', 'Subcategory5', ('Item5', 1.0)],
  ['MainCategory4', 'Subcategory6', ('Item6', 1.0)],
  ['MainCategory5', 'Subcategory7', ('Item7', 1.0)],
  ['MainCategory5', 'Subcategory8', ('Item8', 1.0)],
  ['MainCategory5', 'Subcategory9', ('Item9', 1.0)]],
  
  ['Name3',
  ['MainCategory3', 'Subcategory10', ('Item10', 1.0)], #&lt;-note MainCategory3 again.
  ['MainCategory6', 'Subcategory11', ('Item11', 1.0)]]]
  </code></pre>
  
  <p>I need to get to this. I.e. Names into rows, MainCategories into columns and Items counted into their MainCategories. Subcategories can be discarded.</p>
  
  <p><a href="https://i.stack.imgur.com/Mut46.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mut46.png" alt="enter image description here"></a></p>
  
  <p>How on earth do I do it? I've used Python3 for a short time and I know how to save the above as a csv file ready for Excel, but I don't know how to structure it in the way I want. If I use lists to put all MainCategories into one list, and then item counts into another list, how do I maintain the relationship between the MainCategories and the item counts? Am I supposed to do something else? Maybe use dict? Any help would be appreciated as I have no idea what to do.</p>