Death to tuples!

Mike Meyer mwm at mired.org
Mon Nov 28 15:21:31 EST 2005


Steven Bethard <steven.bethard at gmail.com> writes:
> Dan Bishop wrote:
>> Mike Meyer wrote:
>>
>>>Is there any place in the language that still requires tuples instead
>>>of sequences, except for use as dictionary keys?
>> The % operator for strings.  And in argument lists.
>> def __setitem__(self, (row, column), value):
>>    ...
> Interesting that both of these two things[1][2] have recently been
> suggested as candidates for removal in Python 3.0.
> [1]http://www.python.org/dev/summary/2005-09-01_2005-09-15.html#string-formatting-in-python-3-0
> [2]http://www.python.org/dev/summary/2005-09-16_2005-09-30.html#removing-nested-function-parameters

#2 I actually mentioned in passing, as it's part of the general
concept of tuple unpacking. When names are bound, you can use a
"tuple" for an lvalue, and the sequence on the rhs will be "unpacked"
into the various names in the lvalue:

        for key, value = mydict.iteritems(): ...
        a, (b, c) = (1, 2), (3, 4)

I think of the parameters of a function as just another case of
this; any solution that works for the above two should work for
function paremeters as well.

     <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list