title: Incrementing dict values with dict comprehension
body: <p>I'm trying to do the following expression with dict comprehension and a ternary operation in python:</p>
  
  <pre><code>for num in ar:
       if num in seen_dict:
           seen_dict[num] += 1
       else:
           seen_dict[num] = 1
  </code></pre>
  
  <p>I tried this:</p>
  
  <pre><code>seen_dict = { num: seen_dict[num] += 1 for num in ar if num in seen_dict else seen_dict[num] = 1}
  </code></pre>
  
  <p>and several permutations thereof, but I keep getting syntax errors. Is it possible to do what I want?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>This is the correct syntax, but not my dict only comes back with 1's:
  <code>seen_dict = { num: (seen_dict[num] + 1) if num in seen_dict else 1 for num in ar }</code></p>
  
  <p>Can someone explain why this doesn't function the same way as the for loop? Thank you.</p>