[Python-3000] suggestion: structured assignment

allyourcode at gmail.com allyourcode at gmail.com
Thu May 29 06:51:11 CEST 2008


I just looked through the official tutorial and Dive into Python, and
didn't find anything about it in either of those places. While this
feature is documented in the language reference, it does not seem to
be a well-known feature (another example: at least one other person
did not know about it).

On 5/28/08, allyourcode at gmail.com <allyourcode at gmail.com> wrote:
> Well, I'm sorry for bothering his majesty with such a stupid idea. At
> least one other person didn't know about it either...
>
> On 5/28/08, Mike Klaas <mike.klaas at gmail.com> wrote:
>>
>> On 28-May-08, at 6:23 PM, Daniel Wong wrote:
>>
>>> Currently, I must do the following instead:
>>>
>>> for n, pair in enumerate(list_of_pairs):
>>>  a, b = pair
>>>  ...
>>>
>>> <>
>>> Thoughts?
>>
>> I find it hard to believe that you have even attempted this, which has
>> been valid in python for ages:
>>
>>  >>> for x, (a, b) in enumerate([(1,2), (3,4), (5,6)]):
>>              print x, a, b
>>
>> 0 1 2
>> 1 3 4
>> 2 5 6
>>
>> -Mike
>>
>


More information about the Python-3000 mailing list