dictionary object

Diego Dainese ddainese40x at x44dsi.unive.it
Mon May 10 14:03:48 EDT 1999


Hi,

I have a question regarding the dictionary objects: in a dictionary
where the values are tuples, is it possible to get the tuple with a
given key and to change the value of one element of this tuple using
only one key lookup?

In example, if dict is defined like this:

   value1 = "hello one"
   value2 = "hello two"
   dict = { "pluto" : (10, value1), "pippo" : (20, value2) }

And I want to get the first element of the tuple with the key "pluto"
and change the second element of this same tuple, I must do something
like this:

  num = dict["pluto"][0]
  dict["pluto"]= (num, "hello three")

Thus making two key lookups. There is a better way to do it?

Thanks in advance,

-- 
Diego Dainese
To reply me, remove the numbers and the `x' from my address
Sorry for my bad English!




More information about the Python-list mailing list