memoize factorial example (was Re: decorators ?)

Daniel 'Dang' Griffith google0 at lazytwinacres.net
Tue Dec 7 17:24:04 EST 2004


On Tue, 30 Nov 2004 19:38:46 GMT, "Paul McGuire"
<ptmcg at austin.rr._bogus_.com> wrote:

>"km" <km at mrna.tn.nic.in> wrote in message
>news:mailman.6942.1101835501.5135.python-list at python.org...
>> Hi all,
>>  was going thru the new features introduced into python2.4 version.
>> i was stuck with 'decorators' -  can someone explain me the need of such a
>thing called decorators ?
>> tia
>> KM
>
>Here are some example on the Python Wiki:
>http://www.python.org/moin/PythonDecoratorLibrary
>
>I think memoize is my favorite so far.

Memoize is certainly a readily approachable example.

But the factorial example on the wiki has a defect.  It incorrectly
calculates factorial(0) as 0, when it should be 1.  I don't know how
to edit the "inline" code in the wiki, but if someone out there knows
how, consider changing:

    if n < 2:
        return n

to:

    if n < 2:
        return 1

Have a nice day!
    --dang



More information about the Python-list mailing list