Long integers, xrange and number theory

Terry Reedy tjreedy at udel.edu
Sat Dec 7 21:03:48 EST 2002


"Mark Edward Tristan Dickinson" <dickinsm at umich.edu> wrote in message
news:mailman.1039308250.27019.python-list at python.org...
> The code is at:
>
> http://www.math.lsa.umich.edu/~dickinsm/575f02/ElemNum.py
>
> Lehman() is somewhere in there, at about line 560 or so.

Your utility functions (wrapped reduces) would run faster if you
import operator and use the C-coded functions contained therein
instead of Python-coded lambdas.  IE, change last line of
def sum(numlist):
    """return the sum of a list of numbers"""
    return reduce(lambda x, y : x+y, numlist, 0)
to
    return reduce(operator.add, numlist, 0)

I should think this just as clear to students once explained a bit.

Terry J. Reedy

PS. I like your extension of reduce() to operate on a list of pairs:
"
 A final note:  the function chinese is defined by a
    single line of Python code!  All the work is actually performed
    by a succession of calls to chinesePair."""

    return reduce(chinesePair, congruences, (0,1))
"

PPS. You might follow "
# !!!Please test!!!  Any corrections, suggestions for improvements,
 # requests for extra functionality, etc, would be very welcome."
with an email address to send such.






More information about the Python-list mailing list