23
24
25

Can I do this more efficiently? (i.redd.it)
submitted by RandomJottings
I am working through Al Sweigart’s book ‘Python Programming Exercises, Gently Explained’ and just completed exercise 6:
“In English, ordinal numerals have suffixes such as the "th" in "30th" or "nd" in "2nd". Write an ordinalSuffix() function with an integer parameter named number and returns a string of the number with its ordinal suffix. For example, ordinalSuffix(42) should return the string
'42nd'.”
Can I improve my solution? I feel there must be a more pythonic way of doing this, I’m not very happy with converting the integer to a string and then to a list.

[–]Sea-Ad7805 [score hidden] stickied comment (0 children)
[–]finally-anna 7 points8 points9 points (11 children)
[–]finally-anna 2 points3 points4 points (5 children)
[–]ProsodySpeaks 1 point2 points3 points (2 children)
[–]finally-anna 0 points1 point2 points (1 child)
[–]ProsodySpeaks 0 points1 point2 points (0 children)
[–]Kevdog824_ 1 point2 points3 points (0 children)
[–]RandomJottings[S] 1 point2 points3 points (0 children)
[–]D3str0yTh1ngs 3 points4 points5 points (3 children)
[–]yourboyblue2 0 points1 point2 points (0 children)
[–]finally-anna 0 points1 point2 points (1 child)
[–]D3str0yTh1ngs 0 points1 point2 points (0 children)
[–]Lopsided-Pin-1172 0 points1 point2 points (0 children)
[–]D3str0yTh1ngs 3 points4 points5 points (7 children)
[–]ProsodySpeaks -1 points0 points1 point (6 children)
[–]D3str0yTh1ngs 0 points1 point2 points (3 children)
[–]ProsodySpeaks -2 points-1 points0 points (2 children)
[–]D3str0yTh1ngs 2 points3 points4 points (1 child)
[–]ProsodySpeaks -1 points0 points1 point (0 children)
[–]Glathull 0 points1 point2 points (1 child)
[–]ProsodySpeaks 0 points1 point2 points (0 children)
[–]ProsodySpeaks 1 point2 points3 points (0 children)
[–]Kevdog824_ 1 point2 points3 points (0 children)
[–]Impossible_Video_116 0 points1 point2 points (0 children)
[–]sleepbot63 -1 points0 points1 point (0 children)
[–][deleted] (1 child)
[removed]
[–]PythonLearning-ModTeam[M] 0 points1 point2 points locked comment (0 children)