Re: function call questions

2016-10-23 Thread chenyong20000
在 2016年10月22日星期六 UTC+8下午9:15:06,Frank Millman写道: > wrote in message > news:9c91a4cf-1f3e-43b3-b75c-afc96b0b4...@googlegroups.com... > > > 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

Re: function call questions

2016-10-22 Thread Frank Millman
wrote in message news:9c91a4cf-1f3e-43b3-b75c-afc96b0b4...@googlegroups.com... 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 acc

Re: function call questions

2016-10-22 Thread chenyong20000
在 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, > > >

Re: function call questions

2016-10-22 Thread 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.set

Re: function call questions

2016-10-22 Thread chenyong20000
在 2016年10月20日星期四 UTC+8下午11:04:38,Frank Millman写道: > wrote in message > news:01cfd810-0561-40b1-a834-95a73dad6...@googlegroups.com... > > 在 2016年10月20日星期四 UTC+8下午1:32:18,Frank Millman写道: > > wrote in message > > news:5506e4d8-bd1d-4e56-8d1b-f71fa8293...@googlegroups.com... > > > > > Let's see if I

Re: function call questions

2016-10-21 Thread Frank Millman
"Anssi Saari" wrote in message news:vg3wph2i3dt@coffee.modeemi.fi... 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 change

Re: function call questions

2016-10-21 Thread Anssi Saari
"Frank Millman" writes: > Let's see if I can explain. I am using 't' and 'r' instead of 'tree' > and 'root', but otherwise it is the same as your original example. > t = {} r = t id(t) > 2542235910088 id(r) > 2542235910088 > > At this point, t and r are both references to the

Re: function call questions

2016-10-20 Thread Frank Millman
wrote in message news:01cfd810-0561-40b1-a834-95a73dad6...@googlegroups.com... 在 2016年10月20日星期四 UTC+8下午1:32:18,Frank Millman写道: wrote in message news:5506e4d8-bd1d-4e56-8d1b-f71fa8293...@googlegroups.com... > Let's see if I can explain. I am using 't' and 'r' instead of 'tree' and > 'root', bu

Re: function call questions

2016-10-20 Thread chenyong20000
在 2016年10月20日星期四 UTC+8下午1:32:18,Frank Millman写道: > wrote in message > news:5506e4d8-bd1d-4e56-8d1b-f71fa8293...@googlegroups.com... > > 在 2016年10月19日星期三 UTC+8下午3:17:18,Peter Otten写道: > > chenyong20...@gmail.com wrote: > > > > > 在 2016年10月19日星期三 UTC+8上午11:46:28,MRAB写道: > > >> On 2016-10-19 03:15,

Re: function call questions

2016-10-19 Thread Frank Millman
wrote in message news:5506e4d8-bd1d-4e56-8d1b-f71fa8293...@googlegroups.com... 在 2016年10月19日星期三 UTC+8下午3:17:18,Peter Otten写道: chenyong20...@gmail.com wrote: > 在 2016年10月19日星期三 UTC+8上午11:46:28,MRAB写道: >> On 2016-10-19 03:15, chenyong20...@gmail.com wrote: >> > Thanks Peter and Anssi for your ki

Re: function call questions

2016-10-19 Thread chenyong20000
在 2016年10月19日星期三 UTC+8下午3:17:18,Peter Otten写道: > chenyong20...@gmail.com wrote: > > > 在 2016年10月19日星期三 UTC+8上午11:46:28,MRAB写道: > >> On 2016-10-19 03:15, chenyong20...@gmail.com wrote: > >> > Thanks Peter and Anssi for your kind help. Now I'm ok with the first > >> > question. But the second questi

Re: function call questions

2016-10-19 Thread Peter Otten
chenyong20...@gmail.com wrote: > 在 2016年10月19日星期三 UTC+8上午11:46:28,MRAB写道: >> On 2016-10-19 03:15, chenyong20...@gmail.com wrote: >> > Thanks Peter and Anssi for your kind help. Now I'm ok with the first >> > question. But the second question still confused me. Why "it seems that >> > after root =

Re: function call questions

2016-10-18 Thread chenyong20000
在 2016年10月19日星期三 UTC+8上午11:46:28,MRAB写道: > On 2016-10-19 03:15, chenyong20...@gmail.com wrote: > > Thanks Peter and Anssi for your kind help. Now I'm ok with the first > > question. But the second question still confused me. Why "it seems that > > after root = root.setdefault(ch,{}) tree['a'] and

Re: function call questions

2016-10-18 Thread MRAB
On 2016-10-19 03:15, chenyong20...@gmail.com wrote: Thanks Peter and Anssi for your kind help. Now I'm ok with the first question. But the second question still confused me. Why "it seems that after root = root.setdefault(ch,{}) tree['a'] and root are the same object" and follows tree['a']['b']?

Re: function call questions

2016-10-18 Thread chenyong20000
Thanks Peter and Anssi for your kind help. Now I'm ok with the first question. But the second question still confused me. Why "it seems that after root = root.setdefault(ch,{}) tree['a'] and root are the same object" and follows tree['a']['b']? Thanks. -- https://mail.python.org/mailman/listinf

Re: function call questions

2016-10-18 Thread Peter Otten
chenyong20...@gmail.com wrote: >> > My question is: >> > (1) why root is always {}? >> >> Because that's what you bind it to in the line >> >> > ... root = root.setdefault(ch,{}) >> >> See >> for a description of the the s

Re: function call questions

2016-10-18 Thread chenyong20000
> > My question is: > > (1) why root is always {}? > > Because that's what you bind it to in the line > > > ... root = root.setdefault(ch,{}) > > See > for a description of the the setdefault() method. I'm still confused h

Re: function call questions

2016-10-18 Thread Anssi Saari
chenyong20...@gmail.com writes: > My question is: > (1) why root is always {}? Because that's what you wrote. root.setdefault(ch, {}) returns {} and you assign that to root. You probably want to do just root.setdefault(ch, {}) instead of root = root.setdefault(ch, {}). > (2) why tree is {'a': {'

Re: function call questions

2016-10-18 Thread Peter Otten
chenyong20...@gmail.com wrote: > Hi, > I got a function call as this: > def add_to_tree(root,value_string): > ...print "root is %s, value_string is %s" % (root, value_string) > ...for ch in value_string: > ... print "ch is %s" % ch > ... root = root.setdefault(ch,{}) > ...

function call questions

2016-10-18 Thread chenyong20000
Hi, I got a function call as this: >>>def add_to_tree(root,value_string): ...print "root is %s, value_string is %s" % (root, value_string) ...for ch in value_string: ... print "ch is %s" % ch ... root = root.setdefault(ch,{}) ... print "root is", root ... print "tree is