title: python - how to create dictionary of dictionary in loop
body: <p>I am trying to generate a graph of cities from a file.
  Each <code>readline()</code> I am getting three values, <code>a</code>, <code>b</code>, and <code>c</code>.
  <code>a</code> and <code>b</code> are strings, names of cities, and <code>c</code> is an <code>int</code>, the path cost between <code>a</code> and <code>b</code>.
  How can I store <code>a</code>,<code>b</code>,<code>c</code> so that I get something like </p>
  
  <pre><code>graph = {
            'a1': {'b1': c1, 'b1': 5, 'a2': c2},
            'a2': {'a1': c2},
            'b1': {'a1': c1},
          }
  </code></pre>
  
  <p>Here is part of my code:</p>
  
  <pre><code>dict = dict()   #dictionary for storing values
  while (True):
      new_path = file.readline()
      if new_path == "":
          break
      new_path = new_path.rstrip().split(", ")
      a = new_path[0][2:len(new_path[0]) - 1] #start town
      b = new_path[1][1:len(new_path[1]) - 1] #end town
      c = new_path[2][0:len(new_path[2]) - 1] #path cost
      print(a+" "+b+" "+c)   #this prints Arlington Chelmsford 4
  </code></pre>
  
  <p>.......
    Since I don't know if the key is already in the dictionary, I have tried adding the key with empty value if key is not in <code>dict.keys()</code>, but then <code>update()</code> will function weirdly and give me some sort of list.
    I am new to python so please explain to me how to create such a graph that doesn't include any <code>[]</code> symbol in. Thanks a million!!</p>
  
  <p>the final result I want would be something like this:</p>
  
  <p><code>{'Arlington': {'Chelmsford': 4, 'Berkshire': 10}, 'Chelmsford': {'Arlington': 4, 'Berkshire': 5}, 'Berkshire': {'Arlington': 10, 'Chelmsford': 5}}</code></p>