Last active
October 21, 2019 22:54
-
-
Save tsal/d11387c50daf2fdcaf86ebbcfdee1253 to your computer and use it in GitHub Desktop.
ordinals example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated based on this blog post.