Python dictionaries are awesome
rosuav at gmail.com
Tue Nov 27 07:16:32 CET 2012
On Tue, Nov 27, 2012 at 1:32 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> ... especially when you consider how some other languages implement them.
> Here’s the hypothetical situation: you’re making a flash game. In that
> game users can create named profiles. You store the profiles, keyed by
> their name, so that you ca- OOPS, you just introduced a bug. What’s the
> problem? The dictionary.
> [end quote]
Here's a crazy possibility. What if, instead of just the name, you use
"dictkey_"+name as the key? That's unlikely to conflict with anything.
Hey, I wonder if Adobe might even have been able to do that under the
covers! That would have been really easy, wouldn't have cost much, and
would have given full functionality! (Except that you now can't have a
property named "dictkey_foo", but that could be considered a
misfeature - you can use a dictionary as a sort of jump table.)
Python just happened to get it right by sheer luck, of course. No
designer could possibly foresee problems like that.
More information about the Python-list