In <b078a04b-024b-48dc-b24a-8f4ce75fa...@13g2000vbu.googlegroups.com> Massi 
<massi_...@msn.com> 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
gor...@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to