dict slice assignment with tuples?

Nathan Clegg nathan at islanddata.com
Wed Sep 15 17:45:44 EDT 1999


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]

I would like to be able to do this with a single tuple or list instead. 
So, to accomplish the above, I would like to be able to do something like:

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

This is important because I want to assign the return value of a function
without calling the function multiple times or doing excessive
manipulation of the return value before sticking it in.  I realize I can
do this with map, if necessary, but I would much rather a more concise
solution.  Anything I can do?


----------------------------------
Nathan Clegg
 nathan at islanddata.com






More information about the Python-list mailing list