Thursday, November 25, 2010

Factorial and pub toilets

What on earth could they be doing together in the title?

On / Twitter / irc there are many ways to tell a new user.

Retelling old jokes or resending tired comparisons: just one way of spotting a new user.

Python programming techniques comparison - factorial:

from math import factorial
print factorial(6)

is a concise and modern way of obtaining factorial of 6 in Python.

There is a funny comparison of different approaches, that has made the rounds several times, and here is one version at

I could link to many forums that have posted the same things in 2009, 2007, 2004 and so on.

The point is that whilst it was funny for myself, because it was new to me, it is not very new to the Python community.

And the pub toilets?

Ah in a pub I used to frequent up in Preston, the toilets where located at the end of the bar and a bit difficult to see if you did not know. Slight inconvenience if you were new to the pub, however it did hold one advantage for the pub manageress ... the new drinkers in the pub almost always introduced themselves to her, in asking the way to the toilets.

About math versus cmath or c_math:

If you were doing a large factorial, then you could instead use Cython to give you a less interpreted runtime version of factorial.

If you are wondering about import c_math in the comparison I mentioned, then you might need to read the articles and links which follow. Perhaps you are looking for Cython or a Complex number library for Python.

Links and further reading:

No comments: