[Python-3000] suggestion: structured assignment (original) (raw)

Guido van Rossum guido at python.org
Thu May 29 06:47:59 CEST 2008


Apart from the missing comma after 'big' this is already supported.

The time machine strikes again!

--Guido

On Wed, May 28, 2008 at 6:23 PM, Daniel Wong <allyourcode at gmail.com> wrote:

Hi,

Are there plans for introducing syntax like this: (a, (b[2], c)) = ('big' ('red', 'dog')) It seems quite doable, because Professor Hillfinger at UC Berkeley created pyth, a dialect of Python, which has this feature. See page 10 of the spec he created for his students to implement the language: http://inst.eecs.berkeley.edu/~cs164/sp08/docs/pyth.pdf Of course, this idea could also be applied to 'for' constructs (loops, list comprehensions, and generators) where assignments are implicit. Parallel looping (esp using zip) is a great use case for this. Here's a case that's come up more than once for me that "structured" assignments would solve really nicely: for n, (a, b) in enumerate(listofpairs): ... Currently, I must do the following instead: for n, pair in enumerate(listofpairs): a, b = pair ... This isn't such a great solution, because there's more indirection with the introduction of an otherwise useless variable; and (less significantly) there's an extra line of code that doesn't actually compute anything. Thoughts? Daniel PS: Sorry if this has already been discussed; I'm new to this list and I didn't see this mentioned in PEP 3099, unless it's covered under the LL(1) clause.


Python-3000 mailing list Python-3000 at python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/guido%40python.org

-- --Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-3000 mailing list