title: Creating a complex nested dictionary from multiple lists in Python
body: <p>I am struggling to create a nested dictionary with the following data:</p>
  
  <pre><code>Team,       Group,  ID,  Score,  Difficulty
  OneTeam,    A,      0,   0.25,   4
  TwoTeam,    A,      1,   1,      10
  ThreeTeam,  A,      2,   0.64,   5
  FourTeam,   A,      3,   0.93,   6
  FiveTeam,   B,      4,   0.5,    7
  SixTeam,    B,      5,   0.3,    8
  SevenTeam,  B,      6,   0.23,   9
  EightTeam,  B,      7,   1.2,    4
  </code></pre>
  
  <p>Once imported as a Pandas Dataframe, I turn each feature into these lists:
  <code>teams, group, id, score, diff</code>.</p>
  
  <p>Using this stack overflow answer <a href="https://stackoverflow.com/questions/53526047/create-a-complex-dictionary-using-multiple-lists">Create a complex dictionary using multiple lists</a> I can create the following dictionary:</p>
  
  <pre><code>{'EightTeam': {'diff': 4, 'id': 7, 'score': 1.2},
   'FiveTeam': {'diff': 7, 'id': 4, 'score': 0.5},
   'FourTeam': {'diff': 6, 'id': 3, 'score': 0.93},
   'OneTeam': {'diff': 4, 'id': 0, 'score': 0.25},
   'SevenTeam': {'diff': 9, 'id': 6, 'score': 0.23},
   'SixTeam': {'diff': 8, 'id': 5, 'score': 0.3},
   'ThreeTeam': {'diff': 5, 'id': 2, 'score': 0.64},
   'TwoTeam': {'diff': 10, 'id': 1, 'score': 1.0}}
  </code></pre>
  
  <p>using the code:</p>
  
  <p><code>{team: {'id': i, 'score': s, 'diff': d} for team, i, s, d in zip(teams, id, score, diff)}</code></p>
  
  <p>But what I'm after is having 'Group' as the main key, then team, and then id, score and difficulty within the team (as above).</p>
  
  <p>I have tried:</p>
  
  <p><code>{g: {team: {'id': i, 'score': s, 'diff': d}} for g, team, i, s, d in zip(group, teams, id, score, diff)}</code></p>
  
  <p>but this doesn't work and results in only one team per group within the dictionary:</p>
  
  <pre><code>{'A': {'FourTeam': {'diff': 6, 'id': 3, 'score': 0.93}},
   'B': {'EightTeam': {'diff': 4, 'id': 7, 'score': 1.2}}}
  </code></pre>
  
  <p>Below is how the dictionary should look, but I'm not sure how to get there - any help would be much appreciated!</p>
  
  <pre><code>{'A:': {'EightTeam': {'diff': 4, 'id': 7, 'score': 1.2},
    'FiveTeam': {'diff': 7, 'id': 4, 'score': 0.5},
    'FourTeam': {'diff': 6, 'id': 3, 'score': 0.93},
    'OneTeam': {'diff': 4, 'id': 0, 'score': 0.25}},
   'B': {'SevenTeam': {'diff': 9, 'id': 6, 'score': 0.23},
    'SixTeam': {'diff': 8, 'id': 5, 'score': 0.3},
    'ThreeTeam': {'diff': 5, 'id': 2, 'score': 0.64},
    'TwoTeam': {'diff': 10, 'id': 1, 'score': 1.0}}}
  </code></pre>