How about adding rational fraction to Python?
Thu Feb 28 02:07:37 CET 2008
Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> writes:
> Oh come on. With a function named "mean" that calculates the sum of a
> list of numbers and then divides by the number of items, what else could
> it be?
You have a bunch of marbles you want to put into bins. The division
tells you how many marbles to put into each bin. That would be
an integer since you cannot cut up individual marbles.
> You can always imagine corner cases where some programmer, somewhere, has
> some bizarre need for a mean() function that truncates when given a list
> of integers but not when given a list of floats. Making that the default
> makes life easy for the 0.1% corner cases and life harder for the 99.9%
> of regular cases, which is far from the Python philosophy.
I think it's more important that a program never give a wrong answer,
than save a few keystrokes. So, that polymorphic mean function is
a bit scary. It might be best to throw an error if the args are
all integers. There is no definitely correct way to handle it so
it's better to require explicit directions.
More information about the Python-list