Re: defaultdict's bug or feature?

2009-05-22 Thread Red Forks
Yes, you maybe right. When use defaultdict, should not rely get() method anymore, d[] is just enough. When a function return a defaultdict, but people don't know it, so: d = load_map() # if she call d['a'], everything is OK but # when call d.get('a'), she is always get None. # Why she call

Re: defaultdict's bug or feature?

2009-05-22 Thread Rhodri James
I asked you not to top-post. Please put your replies *below* the messages you're quoting, not above. It's much easier to understand the conversation that we're having if you do that, and much more aggravating if you don't. On Fri, 22 May 2009 09:53:04 +0100, Red Forks redfo...@gmail.com wrote:

Re: defaultdict's bug or feature?

2009-05-22 Thread Red Forks
On Sat, May 23, 2009 at 2:03 AM, Rhodri James rho...@wildebst.demon.co.ukwrote: I asked you not to top-post. Please put your replies *below* the messages you're quoting, not above. It's much easier to understand the conversation that we're having if you do that, and much more aggravating if

defaultdict's bug or feature?

2009-05-21 Thread Red Forks
from collections import defaultdict d = defaultdict(set) assert isinstance(d['a'], set) assert isinstance(d.get('b'), set) d['a'] is ok, and a new set object is insert to d, but d.get('b') won't. It's a bug, or just a feature? I think dict.get() method is just a *safe* version of dict[key],

Re: defaultdict's bug or feature?

2009-05-21 Thread MRAB
Red Forks wrote: from collections import defaultdict d = defaultdict(set) assert isinstance(d['a'], set) assert isinstance(d.get('b'), set) d['a'] is ok, and a new set object is insert to d, but d.get('b') won't. It's a bug, or just a feature? A feature. I think dict.get() method is just a

Re: defaultdict's bug or feature?

2009-05-21 Thread Rhodri James
On Thu, 21 May 2009 13:07:50 +0100, Red Forks redfo...@gmail.com wrote: from collections import defaultdict d = defaultdict(set) assert isinstance(d['a'], set) assert isinstance(d.get('b'), set) d['a'] is ok, and a new set object is insert to d, but d.get('b') won't. It's a bug, or just a

Re: defaultdict's bug or feature?

2009-05-21 Thread Red Forks
You mean 'get' method should not alter the dict, does 'dict[key]' should not alter the dict either? d = defaultdict(set) assert len(d) == 0 print d[1] assert len(d) == 1 auto insert value to dict, when value is not in dict, is what defaultdict try to do. On Fri, May 22, 2009 at 7:46 AM, Rhodri

Re: defaultdict's bug or feature?

2009-05-21 Thread MRAB
Red Forks wrote: You mean 'get' method should not alter the dict, does 'dict[key]' should not alter the dict either? d = defaultdict(set) assert len(d) == 0 print d[1] assert len(d) == 1 auto insert value to dict, when value is not in dict, is what defaultdict try to do. That's the

Re: defaultdict's bug or feature?

2009-05-21 Thread Rhodri James
Please don't top-post, it makes the thread of argument hard to follow. On Fri, 22 May 2009 01:44:37 +0100, Red Forks redfo...@gmail.com wrote: You mean 'get' method should not alter the dict, does 'dict[key]' should not alter the dict either? d = defaultdict(set) assert len(d) == 0 print