Add items in nested dictionaries based on ID number in python
<p>I have dictionaries nested in a list. The dictionaries are set up as follows:</p>

<p><code>{'ID': 123, 'Balance': 45, 'Comments': None}</code></p>

<p>I have multiple of these dictionaries in a list, so the list looks like this:</p>

<pre><code>[{'ID': 123, 'Balance': 45, 'Comments': None}, {'ID': 456, 'Balance': 78, 'Comments': None}]
</code></pre>

<p>What I'm trying to do, is check to see if there is already a dictionary with the ID from the input in the list, and if there is, add the Balance from the input. 
Is there any readable pythonic way to do this?</p>

<p>What I'm hearing here is "how do I get an item from a list, given that I know some unique key value about it?". How much are you committed to keeping the current data structure? I'm inclined to dispense with the list entirely and use a dict-of-dicts.</p>

<pre><code>d = {
    123: {'Balance': 45, 'Comments': None}
    456: {'Balance': 78, 'Comments': None}
}
</code></pre>

<p>now checking if an id exists is just <code>if some_id in d:</code> and adding to the balance is <code>d[some_id]["Balance"] += some_amount</code>.</p>

python list dictionary nested