I have a list of integers - is there a library to convert them into plain text ranking? IE: 1,2,3 -> "first, second, third" ?
The python inflect
package has a method for converting numerals into ordinals:
import inflect p = inflect.engine() for i in range(1,25,5): print(p.ordinal(i))
displays:
1st 6th 11th 16th 21st
How high are you planning on going? (Do you ever expect higher than, say, "twentieth"?)
Maybe you just need a dict
,
nth = { 1: "first", 2: "second", 3: "third", 4: "fourth" # etc }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With