The Artima Developer Community
Sponsored Link

Python Buzz Forum
Python snippet: ordinalth(n)

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Simon Willison

Posts: 282
Nickname: simonw
Registered: Jun, 2003

Simon Willison is a web technology enthusiast studying for a Computer Science degree at Bath Uni, UK
Python snippet: ordinalth(n) Posted: Oct 8, 2003 7:04 AM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Simon Willison.
Original Post: Python snippet: ordinalth(n)
Feed Title: Simon Willison: Python
Feed URL: http://simon.incutio.com/syndicate/python/rss1.0
Feed Description: Simon Willison's Python cateory
Latest Python Buzz Posts
Latest Python Buzz Posts by Simon Willison
Latest Posts From Simon Willison: Python

Advertisement

Blogged so I don't lose it (blogging as external memory):

def ordinalth(n):
    """ 1 => 1st, 2 => 2nd etc """
    last = n - n / 10 * 10
    if last == 1:
        return '%dst' % n
    if last == 2:
        return '%dnd' % n
    if last == 3:
        return '%drd' % n
    return '%dth' % n

Read: Python snippet: ordinalth(n)

Topic: High performance XML-RPC Previous Topic   Next Topic Topic: Invoking qmail-inject from Python on FreeBSD without hanging

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use