2024-04-23 18:22:53 -04:00
|
|
|
#!/usr/bin/env python3 -B
|
|
|
|
# coding=utf-8
|
2022-04-01 10:43:22 -04:00
|
|
|
|
2022-04-17 13:48:43 -04:00
|
|
|
"""
|
2024-04-23 18:22:53 -04:00
|
|
|
Copyright (C) 2022-2024 Plato Mavropoulos
|
2022-04-17 13:48:43 -04:00
|
|
|
"""
|
2022-04-01 10:43:22 -04:00
|
|
|
|
2024-04-23 18:22:53 -04:00
|
|
|
|
2022-04-01 10:43:22 -04:00
|
|
|
def get_ordinal(number):
|
2024-04-23 18:22:53 -04:00
|
|
|
"""
|
|
|
|
Get ordinal (textual) representation of input numerical value
|
|
|
|
https://leancrew.com/all-this/2020/06/ordinals-in-python/ by Dr. Drang
|
|
|
|
"""
|
|
|
|
|
|
|
|
txt = ('th', 'st', 'nd', 'rd') + ('th',) * 10
|
|
|
|
|
|
|
|
val = number % 100
|
|
|
|
|
|
|
|
return f'{number}{txt[val % 10]}' if val > 13 else f'{number}{txt[val]}'
|