New user's initial thoughts / criticisms of Python
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Mon Nov 11 06:17:16 EST 2013
On Mon, 11 Nov 2013 21:39:27 +1100, Chris Angelico wrote:
> My code to handle that starts out with this array:
>
> "minor weapon":({
> 70,"+1 weapon: 2,000gp [weapon]",
> 85,"+2 weapon: 8,000gp [weapon]",
> 90,"Specific weapon [minor specific weapon]", 100,"Special ability
> [minor special weapon] and roll again",
> }),
>
> (that's Pike; in Python it'd be a list, or maybe a tuple of tuples), and
> denormalizes it into a lookup table by creating 70 entries quoting the
> first string, 15 quoting the second, 5, and 10, respectively.
Ewww :-(
Imagine having to print out the dict looking for an error in the lookup
table. Or imagine the case where you have:
0...20000: do this
20001...890001: do that
890001...890003: do something else
Don't get me wrong, it's a clever and reasonable solution for your
specific use-case. But I'd much rather have a lookup table variant that
matches on intervals.
Hmmm... if you had an interval data type, which was hashable, that would
probably be trivial... what am I missing? Ah, of course, what I'm missing
is that although you're storing intervals as the keys, you're matching
regular ints.
I wonder if this would be a good use-case for Antoine Pitrou's
TransformDict?
http://www.python.org/dev/peps/pep-0455/
--
Steven
More information about the Python-list
mailing list