I am a newbie too, but....<div>from collections import defaultdict</div><div><br></div><div>Then you can do:</div><div>data = defaultdict(int)</div><div>Everything (all keys) start at 0, so you can do &quot;+=&quot; with no problem.</div>
<div><br></div><div>I&#39;m sure somebody else has a better solution though!</div><div><br></div><div>Cheers</div><div>Colin<br><br><div class="gmail_quote">On 25 March 2011 18:52, Robert Sjoblom <span dir="ltr">&lt;<a href="mailto:robert.sjoblom@gmail.com">robert.sjoblom@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi again, list! A quick question about dictionary behaviour. I have a<br>
dictionary of keys, and the user should be able to enter values into<br>
said dictionary. My idea was this:<br>
<br>
def addData(key, value):<br>
    dictionary[key] += int(value)<br>
    return None<br>
<br>
dictionary = {&quot;a&quot;:0, &quot;b&quot;:0, &quot;c&quot;:0, &quot;d&quot;:0}<br>
<br>
for key in dictionary:<br>
    a = input(&quot;Enter key: &quot;)<br>
    b = int(input(&quot;Enter value: &quot;))<br>
    try:<br>
        addData(a, b)<br>
    except:<br>
        continue<br>
<br>
Which works fine, but the problem is that I need to ensure that every<br>
key gets a value above 0; the try/except is clearly not doing that<br>
(and it can&#39;t deal with b=int(input(&quot;Enter value:&quot; )) because there&#39;s<br>
no try for that, which I suppose there should be). How would I go<br>
about making sure that each key gets a value above 0 in this case?<br>
Also, is there a better way to do what I&#39;m trying to do than what I&#39;ve<br>
come up with? I&#39;m trying to translate a paper form into data arrays<br>
for later use (and this particular part is simple in comparison to<br>
some other parts where you get one name and multiple values to that<br>
name, which I have no idea how to solve, but I figure one step at a<br>
time, and the current step is this one), but I&#39;m quite the newbie at<br>
programming. Still.<br>
<br>
best regards,<br>
Robert S.<br>
_______________________________________________<br>
Tutor maillist  -  <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><img src="http://projecteuler.net/profile/colspeed.png"><br><br>
</div>