[Chicago] I don't get why this works

Alex Gaynor alex.gaynor at gmail.com
Tue Apr 2 05:46:26 CEST 2013


Sorry, I should have been more precise, first the far right hand side is
evaluated, so you get the string 'b' (of course). Then the assignments are
evaluated left to right.

So first:

a['a'] = 'b'

Then

a[a['a']] = 'b'

Now a['a'] == 'b'

so a['b'] = 'b'.

Alex


On Mon, Apr 1, 2013 at 8:41 PM, Brantley Harris <deadwisdom at gmail.com>wrote:

> Okay, then it should be a key error:
>
> > a['a'] = a[a['a']]
> KeyError: 'a'
>
>
> On Mon, Apr 1, 2013 at 10:25 PM, Alex Gaynor <alex.gaynor at gmail.com>wrote:
>
>> The assignments are going left to right.
>>
>> Alex
>>
>>
>> On Mon, Apr 1, 2013 at 8:24 PM, Brantley Harris <deadwisdom at gmail.com>wrote:
>>
>>> > a = {}
>>> > a['a'] = a[a['a']] = 'b'
>>> {'a': 'b', 'b': 'b'}
>>>
>>> What the what?  I would think that should KeyError, but it runs fine.
>>>  Someone splain.
>>>
>>> _______________________________________________
>>> Chicago mailing list
>>> Chicago at python.org
>>> http://mail.python.org/mailman/listinfo/chicago
>>>
>>>
>>
>>
>> --
>> "I disapprove of what you say, but I will defend to the death your right
>> to say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
>> "The people's good is the highest law." -- Cicero
>>
>> _______________________________________________
>> Chicago mailing list
>> Chicago at python.org
>> http://mail.python.org/mailman/listinfo/chicago
>>
>>
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago
>
>


-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
"The people's good is the highest law." -- Cicero
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20130401/cec5eb15/attachment.html>


More information about the Chicago mailing list