I'm writing a code to identify the subfix for a given number. I have a bunch of if
statements to figure out the subfix. However I thought that a more elegant solution would be a dictionary. So I have the below dictionary:
The issue is, if I write 9 in subfix
, the result is False. How do I access the elements in the tuple in the dictionary?
subfix = {(0, 4, 5, 6, 7, 8, 9, 11, 12, 13): 'th', 1: 'st', 2: 'nd', 3: 'rd'}
For example, I would like to write something simple like:
def subf(a):
if a in subfix:
ending = subfix.get(a)
print('We met on the ',a,ending,'.'sep='')
which would print 'We met on the 1st.' (but doesn't work for 0,4,5,6,7,8,9,11,12,13) How do I get it to work for those elements?