Re: [Python-Dev] performance of {} versus dict()

2012-11-14 Thread Mark Adam
On Wed, Nov 14, 2012 at 8:28 PM, Stephen J. Turnbull wrote: > Chris Angelico writes: > > > >>> {"a":1}+{"b":2} > > > It would make sense for this to result in {"a":1,"b":2}. > > The test is not "does this sometimes make sense?" It's "does this > ever result in nonsense, and if so, do we care?"

Re: [Python-Dev] performance of {} versus dict()

2012-11-14 Thread Mark Adam
On Wed, Nov 14, 2012 at 5:40 PM, Chris Angelico wrote: > On Thu, Nov 15, 2012 at 10:36 AM, Steven D'Aprano wrote: >> On 15/11/12 05:54, Mark Adam wrote: >> Notice that I'm not merging one dict into another, but merging two dicts >> into a third. > > Side p

Re: [Python-Dev] performance of {} versus dict()

2012-11-14 Thread Mark Adam
On Wed, Nov 14, 2012 at 1:37 PM, Xavier Morel wrote: > On 2012-11-14, at 19:54 , Mark Adam wrote: >> >> Merging of two dicts is done with dict.update. > > No, dict.update merges one dict (or two) into a third one. No. I think you need to read the docs. >> How do you

Re: [Python-Dev] performance of {} versus dict()

2012-11-14 Thread Mark Adam
On Wed, Nov 14, 2012 at 12:12 PM, Xavier Morel wrote: > On 2012-11-14, at 18:10 , Mark Adam wrote: >> >> Try the canonical {'x':1}. Only dict allows the special >> initialization above. Other collections require an iterable. > > Other collections don'

Re: [Python-Dev] performance of {} versus dict()

2012-11-14 Thread Mark Adam
On Wed, Nov 14, 2012 at 11:27 AM, R. David Murray wrote: > Maybe it's not good design, but I'll bet you that if it didn't do that, > there would be lots of instances of this scattered around various > codebases: > > def makedict(**kw): > return kw Now that's a good solution and probab

Re: [Python-Dev] performance of {} versus dict()

2012-11-14 Thread Mark Adam
On Wed, Nov 14, 2012 at 11:00 AM, Brian Curtin wrote: > On Wed, Nov 14, 2012 at 10:12 AM, Mark Adam wrote: >> On Wed, Nov 14, 2012 at 3:12 AM, Chris Withers >> wrote: >>> Hi All, >>> >>> A colleague pointed me at Doug's excellent article here: &

Re: [Python-Dev] performance of {} versus dict()

2012-11-14 Thread Mark Adam
On Wed, Nov 14, 2012 at 11:02 AM, Xavier Morel wrote: > > On 2012-11-14, at 17:42 , Richard Oudkerk wrote: > >> On 14/11/2012 4:23pm, Serhiy Storchaka wrote: >>> PEP 8 recommends: >>> >>> a_dict = dict( >>> x=1, >>> y=2, >>> z=3, >>> ... >>> ) >>> >>> and >>> >>> a_dict = { >>>

Re: [Python-Dev] performance of {} versus dict()

2012-11-14 Thread Mark Adam
On Wed, Nov 14, 2012 at 3:12 AM, Chris Withers wrote: > Hi All, > > A colleague pointed me at Doug's excellent article here: > ...which made me a little sad, I suspect I'm not the only one who finds: > > a_dict = dict( > x = 1, > y = 2, > z = 3, > ... > ) > > ...easier to read