I needed a simple logarithmic based tag cloud where the frequency of the tags was weighted logarithmically. This means that lower frequency tags get dampened down into the same font size and higher frequency tags are popped out in a tag cloud.

def tag_weight(x):
    if x==None or x==0:
         x = 1
    return weight * math.log(x, math.e)

It is pretty simple. It protects against a None or 0 as putting either of those into the log function would result in a ValueError.

The 'weight' variable can be fixed or calculated and is a means to add a formula to the log output to make the tag cloud look good to a human eye when displayed on the page. I use the output of the tag_weight() function in the style attribute of li with with font-size and em.
Logarithmic tag cloud using Python. (more)
Cam Riley: South Sea Republic. Freedom, liberty, equity and an Australian Republic.