title: Read CSV data and add it into dictionary
body: <p>This is an empty Dictionary</p>
  
  <pre><code>d = {}
  </code></pre>
  
  <p>This is the csv file data</p>
  
  <pre><code>M, Max, Sporting, Football, Cricket
  M, Jack, Sporting, Cricket, Tennis
  M, Kevin, Sporting, Cricket, Basketball
  M, Ben, Sporting, Football, Rugby
  </code></pre>
  
  <p>I tried to use the following code to append data from the csv to dictionary.</p>
  
  <pre><code>with open('example.csv', "r") as csvfile:
          csv_reader = csv.reader(csvfile)
          for row in csv_reader:
              if row:
                  d.setdefault(row[0], {})[row[1]] = {row[2]: [row[3]]}
  </code></pre>
  
  <p>But it gives me an error:</p>
  
  <pre><code>d.setdefault(row[0], {})[row[1]] = {row[2]: [row[3]]}
  IndexError: list index out of range
  </code></pre>
  
  <p>It there any way, i can add data from csv to the dictionary, in the form:</p>
  
  <pre><code>d = {'M': {'Max': {'Sporting': ['Football', 'Cricket']}, 'Jack': {'Sporting': ['Cricket', 'Tennis']}}}
  </code></pre>
  
  <p>I am new to this so help me.</p>