在 2016年10月22日星期六 UTC+8下午5:06:22,Frank Millman写道:
> wrote in message 
> news:2853d778-857e-46fc-96a0-8d164c098...@googlegroups.com...
> 
> 在 2016年10月20日星期四 UTC+8下午11:04:38,Frank Millman写道:
> > wrote in message
> > news:01cfd810-0561-40b1-a834-95a73dad6...@googlegroups.com...
> >
> > Hi Frank,
> >
> > thanks for your kind help. What confused me is at this line:
> >
> > >>> r = r.setdefault('b', {})
> >
> > and its previous one
> >
> > >>> r = r.setdefault('a', {})
> >
> > When r.setdefault('a',{}) is run, I understand it will return an empty {}. 
> > At this time both r & t reference to {'a':{}}, right? So when "r = 
> > r.setdefault('a',{})" is run, r reference to {} while t keeps the same as 
> > {'a':{}}.
> >
> > then comes r.setdefault('b',{}). What hinder me is here. since r has 
> > changed its reference to {}, r.setdefault('b',{}) will return {} again. So 
> > what does this done to t? why at this time t changes to {'a':'b':{}}? 
> > Sorry for my silly here. Thanks
> >
> 
> I don't know if you have been following the other posts in this thread.
> 
> There were some posts from Anssi Saari who was also confused by this, but 
> then yesterday he sent a post saying that he has now 'got it'.
> 
> I don't think I can do better than quote his explanation of what is 
> happening -
> 
> """
> OK, so what happens is that now t references the dictionary with {'a': {}} 
> and r references the empty dict inside that.
> 
> So when we assign to r again, it's the empty dict inside t (the one accessed 
> by key 'a') that changes to {'b': {}} and t becomes {'a': {'b': {}}}.
> """
> 
> That is exactly right.
> 
> Does that help?
> 
> Frank

Hi Frank,

I have read Anssi's post already before I sent the post. To be frankly, I can't 
understand why he got the right answer. I'm sorry for my silly. "So when we 
assign to r again, it's the empty dict inside t (the one accessed 
by key 'a')". I do can't understand why this happens. that is the reason why I 
have asked for this once again and again. There must be some import point I 
missed but I don't what is it.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to