Skip to content

Instantly share code, notes, and snippets.

@tsal

tsal/ordinals.py

Last active Oct 21, 2019
Embed
What would you like to do?
ordinals example
def switch_suffix(digit):
switch = {
1: "st",
2: "nd",
3: "rd",
}
return switch.get(digit % 10, "th")
ordinals = [i+1 for i in range(10)]
for num in ordinals:
print(f"{num}{switch_suffix(num)}")
@tsal

This comment has been minimized.

Copy link
Owner Author

@tsal tsal commented Oct 21, 2019

output:

1st
2nd
3rd
4th
5th
6th
7th
8th
@tsal

This comment has been minimized.

Copy link
Owner Author

@tsal tsal commented Oct 21, 2019

Updated based on this blog post.

@tsal

This comment has been minimized.

Copy link
Owner Author

@tsal tsal commented Oct 21, 2019

... and fixed a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment