[Python-Dev] Tuple/list assignment question (original) (raw)

James Y Knight foom at fuhm.net
Thu Aug 5 18:10:34 CEST 2004


On Aug 3, 2004, at 2:44 AM, Dave Cole wrote:

>>> alist = [1, 2, 3, 4, 5] >>> a, b, *c = alist

While you're proposing expanding the domain of the * construct of function calling to other parts of python, I'd also like to suggest the following features, to make the ** construct also applicable to the rest of the language.

To be read with an 70% wink. (I wouldn't be unhappy if these were in python, but I am not seriously proposing these features for inclusion):

Dict unpacking, parallels current sequence unpacking:

d = {'foo': 1, 'bar': 2} {'foo': x, 'bar': y} = d x, y (1, 2)

Dict interpolation, similar to sequence interpolation and keyword interpolation in function calls:

d = {'foo': 1, 'bar': 2} d2 = {'baz': 3, **d} d2 {'baz': 3, 'foo': 1, 'bar': 2}

Combining the two:

d = {'foo': 1, 'bar': 2, 'baz': 3} {'foo': x, 'bar': y, **d2} = d x, y, d2 (1, 2, {'baz': 3})

James



More information about the Python-Dev mailing list