[Tutor] operator, mult

col speed ajarncolin at gmail.com
Wed Jan 28 02:07:19 CET 2009


Hello there,
 I got the following function while googling:

def totient(n):
    """calculate Euler's totient function.

    If [[p_0,m_0], [p_1,m_1], ... ] is a prime factorization of 'n',
    then the totient function phi(n) is given by:

        (p_0 - 1)*p_0**(m_0-1) * (p_1 - 1)*p_1**(m_1-1) * ...

    >>> phi(1)
    1
    >>> phi(10)
    4
    """
    from operator import mult

    if n == 1: return 1

    return reduce(mult, [(p-1) * p**(m-1) for p,m in prime_factors_mult(n)])


I already have the "prime_factors" function. The problem is that I cannot
find "mult". I tried using "mul" which is in "operator" but that is
obviously not the same thing.
Could there be a similar thing somewhere other than "operator"?

Thanks a lot
Colin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090128/fc32dd48/attachment.htm>


More information about the Tutor mailing list