fork(2) download
  1. import re
  2. def transform(text):
  3. dct = {'January':'01','February':'02','March':'03','April':'04','May':'05','June':'06','July':'07','August':'08','September':'09','October':'10','November':'11','December':'12'}
  4. output, n = re.subn(rf'\b(?:{"|".join(dct.keys())})\b', lambda x: dct[x.group()], text)
  5. if not n:
  6. return('This is a string without a month in it')
  7. else:
  8. return output
  9.  
  10.  
  11. print( transform('I was born on June 24 and my sister was born on May 17') )
  12. # expected output: 'I was born on 06 24 and my sister was born on 05 17'
  13.  
  14. print( transform('This is a string without a month in it') )
  15. # expected output: 'This is a string without a month in it'
Success #stdin #stdout 0.02s 9516KB
stdin
Standard input is empty
stdout
I was born on 06 24 and my sister was born on 05 17
This is a string without a month in it