destructuring tuple and list

Diez B. Roggisch deetsNOSPAM at web.de
Wed Mar 17 06:31:52 EST 2004


Sebastien de Menten wrote:

> Hi,
> 
> Is there a reason to not extend the tuple destructuration in functions
> to any expression ?
> For instance, we can:
> def f(x, y, *tail):
> return tail + (x,y)
> f(3,4,5,6) -> (5,6,3,4)
> or
> f(*(3,4,5,6)) -> idem
> 
> But I can't do:
> (x,y, *tail) = (3,4,5,6)
> and get
> x=3
> y=4
> tail = (5,6)
> Same question for lists...


I've also thought about that. s/t like real pattern matching might be cool,
but is probably too much of a paradigm shift.   

What I do is this:

l = (5,6,3,4)
x,y,tail = l[0:2], l[:2]

IMHO not too ugly....
        
-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list