fork(3) download
  1. import re
  2. input = ['90-10-07457', '000480087800784', '001-713-0926', '12-710-8197', '1-345-1715', '9-23-4532', '000200007100272']
  3. output = ['00090-00010-07457', '000480087800784', '00001-00713-00926', '00012-00710-08197', '00001-00345-01715', '00009-00023-04532', '000200007100272']
  4.  
  5. ## I have tried this -
  6.  
  7. import re
  8. new_list = []
  9. for i in range (0, len(input)):
  10. new_list.append(re.sub(r'^(\d+)-(\d+)-(\d+)$', lambda x: "{}-{}-{}".format(x.group(1).zfill(5), x.group(2).zfill(5), x.group(3).zfill(5)), input[i]))
  11.  
  12. ## problem is with second argument '0000\\1'. I know its wrong but unable to solve
  13. print(new_list) ## new_list is the expected output.
  14. print(output)
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
['00090-00010-07457', '000480087800784', '00001-00713-00926', '00012-00710-08197', '00001-00345-01715', '00009-00023-04532', '000200007100272']
['00090-00010-07457', '000480087800784', '00001-00713-00926', '00012-00710-08197', '00001-00345-01715', '00009-00023-04532', '000200007100272']