You need the min
built-in method
suffixes = ["st", "nd", "rd", "th"]
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
suffix_max_idx = len(suffixes) - 1 # Pre-calculate this to make it faster
combined = []; # Holder for the finished product
# Use enumerate because we're going to need the index value
for num_idx, num in enumerate(numbers):
# Get the suffix index, until the `num_idx` is greater than `suffix_max_idx`
# it will match along with the `num_idx` value.
suffix_idx = min([num_idx, suffixes_max_idx])
suffix = suffixes[suffix_idx]
combined.append(f'{str(num)}{suffix})
Same thing more concise with list comprehension
suffixes = ["st", "nd", "rd", "th"]
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
combined = [
f'{n}{suffixes[min([i, len(suffixes) - 1])]}' for i, n in enumerate(numbers)
]
print(combined)
# ['1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th', '10th']