[Tutor] Using a dict value in the same dict
Alan Gauld
alan.gauld at btinternet.com
Tue Jul 5 19:42:26 CEST 2011
"Válas Péter" <sulinet at postafiok.hu> wrote
> I have a dictionary with the keys 'a' and 'b'. It is not in a class.
> May I use the value of 'a' when defining the value of 'b'?
> If so, what is the syntax?
single = {'a': 1,
'b': 2
}
double = { 'a': single['a'] *2,
'b' : single['b'] * 2
}
single['c'] = 3
double['c'] = single['c'] * 2
Does that help?
Is that what you mean?
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list