[Chicago] I don't get why this works

Randy Baxley randy7771026 at gmail.com
Tue Apr 2 05:54:30 CEST 2013


That is fun.

>>> a = {}
>>> a['a'] = a[a['a']] = 'b'
>>> a
{'a': 'b', 'b': 'b'}

does indeed work the same as:

>>> a = {}
>>> a['a'] = 'b'
>>> a
{'a': 'b'}
>>> a['a']
'b'
>>> a[a['a']] = 'b'
>>> a
{'a': 'b', 'b': 'b'}


On Mon, Apr 1, 2013 at 10: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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20130401/7d5d34a5/attachment.html>


More information about the Chicago mailing list