dict slice assignment with tuples?

William Tanksley wtanksle at dolphin.openprojects.net
Wed Sep 15 20:15:37 EDT 1999


On Wed, 15 Sep 1999 14:45:44 -0700 (PDT), Nathan Clegg wrote:
>I appreciate python's ability to assign several values to several keys in
>a dictionary, such as in:

>a = {}
>a['b', 'c', 'd'] = [4, 5, 6]

Before you go on, I have to warn you that this may not be doing what you
expect.  It's actually not creating several keys; it's creating a single
key, whose value is ('a','c','d').

What you're expecting would be kinda nice, no doubt.  IIRC, you can get it
with:

a = {}
a.update( { 'b':4, 'c':5, 'd':6 } )

Yup, that seems to work.

-- 
-William "Billy" Tanksley




More information about the Python-list mailing list