[CentralOH] Syntactic Sugar (or sacharine)?

Jon Miller jonebird at gmail.com
Fri Aug 12 18:55:46 CEST 2011

If I were working with the same codebase, I would probably ask you to
change it... a bit too clever for my tastes for not much value. If I
wanted the convenience of not typing quotes, I'd probably suggest:

>>> class dummy(): pass
>>> d = dummy()
>>> d.min = 0

-- Jon Miller

On Fri, Aug 12, 2011 at 12:39 PM, Mark Erbaugh <mark at microenh.com> wrote:
> I'm using a dict to store some parameters. I accidentally initialized the dict with {min:0} rather than {'min':0}, but the former worked as the built-in function min is hashable and thus suitable as a key. This saves me from having to type quotes in when I retrieve the value  (i.e. info[min] rather than info['min']). I'm thinking it's marginally faster as there's no string processing involved.  The only downside I can come up with is that the min function is not being used as intended and it could be confusing.
> The same principle allows you to create objects to be used as dictionary keys to make the [key] lookup syntax cleaner.
> What do people think about this?
> class A: pass
> class B: pass
> d = {A:'value for A', B:'value for B'}
> Mark
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> http://mail.python.org/mailman/listinfo/centraloh

More information about the CentralOH mailing list