On 3/7/06, Andrew Koenig <[EMAIL PROTECTED]> wrote:
> As it turns out, Python has similar ways of decomposing data structures:
>
> (x, y) = foo
>
> or
>
> def bar((x, y)):
> # etc.
>
> and I have sometimes wished I could write
>
> z as (x, y) = foo
>
> or
>
> def bar(z as (x, y)):
> # etc.
>
> However, it's not real high on my list of priorities, and I suspect that
> many Pythonists consider these usages to be a frill anyway.
For the assignment case, you can do this:
>>> foo = (1,2)
>>> (x,y) = z = foo
>>> x
1
>>> y
2
>>> z
(1, 2)
>>>
Function arguments are not covered by this trick, but
def bar(z):
(x,y) = z
probably isn't too much overhead...
(Or did I miss your point?)
Paul.
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com