Skip to content

Instantly share code, notes, and snippets.

@tsal
Last active October 21, 2019 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsal/d11387c50daf2fdcaf86ebbcfdee1253 to your computer and use it in GitHub Desktop.
Save tsal/d11387c50daf2fdcaf86ebbcfdee1253 to your computer and use it in GitHub Desktop.
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
Copy link
Author

tsal commented Oct 21, 2019

output:

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

@tsal
Copy link
Author

tsal commented Oct 21, 2019

Updated based on this blog post.

@tsal
Copy link
Author

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