keys in dictionary
"Martin v. Löwis"
martin at v.loewis.de
Tue Nov 22 00:57:38 EST 2005
Shi Mu wrote:
> I run the following code and got wrong message, but I still want to
> make [1,2],[4,3] and [6,9] to be keys of the dictionary or change the
> style a little bit. How to do that?
Make them tuples:
>>> p=[[1,2],[4,3],[6,9]]
>>> n=dict([(tuple(x),[]) for x in p])
>>> n
{(6, 9): [], (1, 2): [], (4, 3): []}
Regards,
Martin
P.S. Please don't cross-post.
More information about the Python-list
mailing list