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

Oleg Broytman phd at phdru.name
Wed Nov 14 17:20:55 CET 2012


On Wed, Nov 14, 2012 at 10:12:54AM -0600, Mark Adam <dreamingforward at gmail.com> wrote:
> On Wed, Nov 14, 2012 at 3:12 AM, Chris Withers <chris at simplistix.co.uk> 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 than:
> >
> > a_dict = {
> >     'x':1,
> >     'y':2,
> >     'z':3,
> >     ...
> >     }
> 
> Hey, it makes me a little sad that dict breaks convention by allowing
> the use of unquoted characters (which everywhere else looks like
> variable names) just for a silly typing optimization.

   It doesn't. It's a call (function call or or a class instantiation)
and it's not dict-specific: function(a=1, b=None)...

Oleg.
-- 
     Oleg Broytman            http://phdru.name/            phd at phdru.name
           Programmers don't die, they just GOSUB without RETURN.


More information about the Python-Dev mailing list