[Tutor] dictionary entries within dictionary
Reggie Dugard
reggie@merfinllc.com
Mon Apr 7 21:17:04 2003
--=-CQbFXlPxH5uXK0tZXZQE
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
Paul,
I'm assuming that self.__styles_num is 15 and that is what is causing
you the problem. If that is the case, you can do what you want in one
of at least 2 ways:
x =3D self.__styles_dict[self.__type_of_style]
if self.__styles_num not in x:
x[self.__styles_num] =3D {}
x[self.__styles_num][att] =3D value
=09
or
self.__styles_dict[self.__type_of_style].setdefault(self.__styles_num,
{}) =3D value
I hope I interpreted your question correctly and this will be of some
use to you.
On Mon, 2003-04-07 at 17:58, Paul Tremblay wrote:
> I can't figure out how to set up and access dictionaries within
> dictionaries.
>=20
> I set up my dictionary as follows:
>=20
> self.__styles_dict =3D {'para': {0:{}}, 'char':{0:{}}}
>=20
> Then try to add a value to this dictionary:
>=20
> self.__styles_dict[self.__type_of_style][self.__styles_num][att] =3D valu=
e
>=20
> I get an error message that key 15 cannot be found. In other words, I
> can't add a value to the inside entry of the dictionary.
>=20
> How do I do this?
>=20
> Thanks
>=20
> Paul
--=20
Reggie
--=-CQbFXlPxH5uXK0tZXZQE
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQA+kiLxkeFt9Tpkup0RAjTtAKCf56KkE3g3+w1UXeDljbXOYaxCAwCfZ4P9
8sycimzOxk+ktjQZFQ7OuwM=
=GzyX
-----END PGP SIGNATURE-----
--=-CQbFXlPxH5uXK0tZXZQE--