dictionary object

Diego Dainese ddainese32x at x11dsi.unive.it
Tue May 11 13:06:37 EDT 1999


On Mon, 10 May 1999 19:02:21 GMT, Christian Tismer wrote:
[...]
> >    value1 = "hello one"
> >    value2 = "hello two"
> >    dict = { "pluto" : (10, value1), "pippo" : (20, value2) }
> > 
[...]
> >   num = dict["pluto"][0]
> >   dict["pluto"]= (num, "hello three")
> > 
> > Thus making two key lookups. There is a better way to do it?
> 
> You would like to change a tuple but cannot change a tuple.
> So how about a list? :-)
> 
> dict = { "pluto" : [10, value1], "pippo" : [20, value2] }
> 
> dict["pluto"][-1] = "what was the question?"
> 

Ooops, you are right, I have simplified too much the program I'm
writing, sorry!

The problem is that the element of the tuple that I must change, must
be changed based on the other element of the tuple.

In example:

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

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

The problem is that I must do two key lookup in the dictionary, one to
retrieve the tuple and one to "change" it.

bye,

-- 
d i e g o
--
To reply remove the numbers and the `x' from my address
--
Sorry for my bad English!




More information about the Python-list mailing list