title: Grouping a text file by a word in Python (Limited to using lists)
body: <p>I'm new to python and I was wondering how you would group a text file by a single word. For example say my text file looks like this:</p>
  
  <pre><code>eggs monday $5 john
  bread monday $3 harry
  bananas wednesday $2 john
  milk saturday $4 sally
  tomatoes sunday $7 sally
  </code></pre>
  
  <p>In my case I want to group the file by names. So for John, for example, I want it to be shown like so:</p>
  
  <pre><code>[john,[eggs,monday],[bananas,wednesday]]
  </code></pre>
  
  <p>and so on for harry and sally. </p>
  
  <p>So right now my code looks like this and I've been able to identify the necessary things (namely name, item, and day) but I'm confused as to how I can group it.</p>
  
  <pre><code>def grocery():
      file = open('shopping.txt')
  
      wholelist = []
      innerlist = [] 
  
      for line in file:
          lines = line.split()
          name = lines[3]
          item = lines[0]
          day = lines[1]
  </code></pre>
  
  <p>Thank you in advance. Also I am limited to using a list within a list so I'm not allowed to use dictionaries.</p>