title: Nested list to nested dictionary in python
body: <p>I have what seems to be a tricky question, but probably quite a simple solution.</p>
  
  <p>I have a nested list that I wish to have the first value of every list contained to be the key within a dictionary. I wish to have every other element contained within that list to be added as a value to that key.</p>
  
  <p>Here is a sample of the nested list:</p>
  
  <pre><code>stations[[1, 'carnegie', 12345, 30],[2, 'london', 12344, 30], [4, 'berlin', 1345563, 30]]
  </code></pre>
  
  <p>I wish to convert this to a dictionary in the following format:</p>
  
  <pre><code>stations {1:['carnegie', 12345, 30], 2:['london', 12344, 30], 4:['berlin', 1345563, 30]}
  </code></pre>
  
  <p>The nested list is quite large, so I've only included as sample here :)</p>
  
  <p>My current attempts have yielded the best option as:</p>
  
  <pre><code>newDict = dict.fromkeys(stations,{})
  </code></pre>
  
  <p>Which gives me:</p>
  
  <pre><code>{1: {}, 2:{}, 4:{}}
  </code></pre>
  
  <p>To which I'm at a loss how to combine both the keys and values to make my ideal dictionary.</p>
  
  <p>Any help on this would be great.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>To add, I'd like to be able to assign a variable name to the dictionary as with the current solution provided below:</p>
  
  <pre><code>{i[0] : i[1:] for i in stations}
  </code></pre>
  
  <p>This give me the correct output in a loop, but when I assign a variable to it in the loop it gives me the final key:value in the dictionary</p>
  
  <pre><code>newDict = {}
   for y in stations:
     newDict = {y[0] : y[1:]}
  
  print newDict
  </code></pre>
  
  <p>returns:</p>
  
  <pre><code>{4: ['berlin', 1345563, 30]}
  </code></pre>
  
  <p>Thanks!</p>