In <[email protected]> Massi
<[email protected]> writes:
> in my script I have a dictionary whose items are couples in the form
> (string, integer values), say
> D = {'a':1, 'b':2, 'c':3}
> This dictionary is passed to a function as a parameter, e.g. :
> def Sum(D) :
> return D['a']+D['b']+D['c']
> Is there a way to create three variables dynamically inside Sum in
> order to re write the function like this?
Do you want to sum all the values in D? If so, that's easy:
def Sum(D):
my_sum = 0
for item in D:
my_sum += D[item]
return my_sum
--
John Gordon A is for Amy, who fell down the stairs
[email protected] B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
--
http://mail.python.org/mailman/listinfo/python-list