A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-March/062147.html below:

[Python-Dev] "as" mania

[Python-Dev] "as" maniaPaul Moore p.f.moore at gmail.com
Tue Mar 7 21:49:27 CET 2006
On 3/7/06, Andrew Koenig <ark at acm.org> 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.
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4