Accessing Dictionary values from within the Dictionary

Robin Becker robin at jessikat.fsnet.co.uk
Fri Nov 15 07:17:41 EST 2002


In article <h10B9.797$v14.274678940 at newssvr30.news.prodigy.com>, Kuros
<kuros at pgtv.net> writes
>Hi again,
>
>I have created a dictionary, like so:
>
>dict = {var1 : 0, var 2: 0}
>
>Now, i want the third key/value pair to equal the total values of var1 and 
>var2. I tried to do it this way:
>
>dict = {var1 : 1, var 2 : 2, var3 : dict[var1] + dict[var2]}
>
>But I get an invalid syntax error.
>
>Could someone help me out with this?
>
>Thanks,
>Kuros
two statements will work
dict = {var1: 0, var2: 0}
dict[var3] = dict[var1] + dict[var2]

-- 
Robin Becker



More information about the Python-list mailing list