title: PYTHON - creating multiple lists in a loop
body: <p>I'm trying to put together a programming project at my university, but I'm stuck. The "math" part I've got covered, but I need help with lists and loops in Python.</p>
  
  <p>I'm working with graphs, let me show one example, to make it clearer:
  <a href="http://i.stack.imgur.com/W64QU.png" rel="nofollow">3 node graph</a></p>
  
  <p>As you can see, I have 3 nodes in it and 2 edges, nothing fancy. I need to compute the closest route between each pair of nodes, and I have that covered already. Now I need to put it either in <strong><em>n</em></strong> lists, <strong><em>n</em></strong> elements each, or in a <strong><em>n x n</em></strong>, so either:</p>
  
  <pre><code>a = [0, 1, 2]
  b = [1, 0, 1]
  c = [2, 1, 0]
  </code></pre>
  
  <p>or a table (or matrix?) like this:
  <a href="http://i.stack.imgur.com/bFBox.png" rel="nofollow">table 3x3</a>, where I only really need the part with the white background.</p>
  
  <p>When I read data to work on, I put each node into a list, as a new element, so with these 3 steps I gradually get:</p>
  
  <pre><code>lw = []
  lw = ['a']
  lw = ['a','b']
  lw = ['a','b','c']
  </code></pre>
  
  <p>Is there any way, to create empty lists out of elemnts of <strong><em>lw</em></strong>? I would really like to name them like <strong><em>dis_a</em></strong>, <strong><em>dis_b</em></strong>, <strong><em>dis_c</em></strong> etc. I tried to do it with a dictionary, but then I couldn't manipulate with those lists, like I usually do. And truth be told, I'd much prefer the solution using lists, as I already have a latter part of the program written for this.</p>
  
  <p>EDIT:
  Ok, so one of you asked for input/output to make my question clearer. Mmy input is:</p>
  
  <pre><code>lw = ['a','b','c']
  </code></pre>
  
  <p>my desired output is:</p>
  
  <pre><code>a = []
  b = []
  c = []
  </code></pre>
  
  <p>or something like that (lists that can be easly identified with the nodes, that I have listed in <strong><em>lw</em></strong>)</p>
  
  <p>EDIT2:</p>
  
  <p>Ok, so now I have a number of lists created like this (still sticking to the example):</p>
  
  <pre><code>dis['a']
  dis['b']
  dis['c']
  </code></pre>
  
  <p>I have a working command </p>
  
  <pre><code>path[X][Y]
  </code></pre>
  
  <p>which on input takes the names of the nodes (as in <strong><em>lw</em></strong> list ex. 'a'), and on input returns a list of </p>
  
  <p>nodes on the shortest path from X to Y. What I need to be doing now, is to take the length of it with</p>
  
  <pre><code>len(path[X][Y])
  </code></pre>
  
  <p>And substract 1 from it (it's counting the "starting" point as well, so it's correcting it). Then I have </p>
  
  <p>to put this number in a corresponding place in a list. I would like to do it in a loop, so it would </p>
  
  <p>automatically append numbers to existing lists, so I would automatically get from</p>
  
  <pre><code>dis['a'] = []
  dis['b'] = []
  dis['c'] = []
  </code></pre>
  
  <p>to</p>
  
  <pre><code>dis['a'] = [0, 1, 2]
  dis['b'] = [1, 0, 1]
  dis['c'] = [2, 1, 0]
  </code></pre>
  
  <p>Don't worry, about it calculating the path twice (ex. from <strong><em>a</em></strong> to <strong><em>b</em></strong> and then from <strong><em>b</em></strong> to <strong><em>a</em></strong>), It doesn't have to be perfect ;) I tried to create such method, but I have no idea, how to store the results in said lists (or if I'm even correct). Here is my proposition:</p>
  
  <pre><code>def lo():   
      for i in range(0, len(lw)):
          for j in range (0, len(lw)):
          dis[i].append(path[lw[i]][lw[j]])
  </code></pre>