title: Sum keys in a dictionary
body: <p>The following code:</p>
  
  <pre><code>for j in reversed(range(0,15)):
    print i
    successors = g.successors(totuple(total_nodes[j,:]))
    array = [0,0,0,0]
    a=0
    i = i+1
  
    for succ in successors:
      print g.node[succ]
      array[a]=g.node[succ]
      a+=1      
  
      print array
      print sum(item['key'] for item in array)
  </code></pre>
  
  <p>produces the following output:</p>
  
  <pre><code> 1
   {'key': 0.0}
   {'key': 0.39730768970355257}
   {}
   {'key': 0.0}
  
   [{'key': 0.0}, {'key': 0.39730768970355257}, {}, {'key': 0.0}]
  </code></pre>
  
  <ol>
  <li>I don't get why some nodes don't have keys {}. But suppose I want to disregard those.</li>
  <li>I want to sum those values or 'keys'</li>
  </ol>
  
  <p>So based on other questions I tried: </p>
  
  <ol>
  <li><p><code>print sum(item['key'] for item in array)</code> produces:</p>
  
  <blockquote>
    <p>KeyError: 'key'</p>
  </blockquote></li>
  <li><p><code>print sum([i for i in array.values()])</code> produces:</p>
  
  <blockquote>
    <p>AttributeError: 'list' object has no attribute 'values'</p>
  </blockquote></li>
  </ol>