fork(1) download
  1. import re
  2. import datetime
  3.  
  4. inp = '''
  5. 6 Jan @ 4:03pm
  6. 8 Jan @ 2:17pm
  7. 9 Dec @ 4:00am
  8. 9 Dec @ 5:14pm
  9. 9 Dec @ 5:28am
  10. 10 Jan @ 2:55pm
  11. 10 Jan @ 4:21am
  12. 10 Jan @ 7:14pm
  13. 12 Dec @ 7:48pm
  14. 12 Dec @ 7:50pm
  15. 12 Jan @ 3:32pm
  16. 13 Dec @ 3:43pm
  17. 13 Dec @ 5:02am
  18. 13 Dec @ 5:24am
  19. 14 Jan @ 5:17pm
  20. 15 Jan @ 5:29am
  21. 21 Dec @ 3:56pm
  22. 21 Dec @ 9:40am
  23. '''
  24.  
  25. regex = re.compile(r'(\d+ \w+) @ (\d+:\d+)(\w[m])')
  26. dates = regex.findall(inp)
  27.  
  28. listofdates = []
  29. out = []
  30.  
  31. for i in range(0, len(dates)):
  32. dt = datetime.datetime.strptime(dates[i][0] + ' ' + dates[i][1] + dates[i][2], "%d %b %I:%M%p")
  33. listofdates.append(dt)
  34.  
  35. listofdates.sort()
  36.  
  37. for i in range(len(listofdates)):
  38. at = listofdates[i].strftime('%d %b @ %I:%M%p')
  39. out.append(at)
  40.  
  41. print('\n'.join(out))
Success #stdin #stdout 0.06s 10704KB
stdin
Standard input is empty
stdout
06 Jan @ 04:03PM
08 Jan @ 02:17PM
10 Jan @ 04:21AM
10 Jan @ 02:55PM
10 Jan @ 07:14PM
12 Jan @ 03:32PM
14 Jan @ 05:17PM
15 Jan @ 05:29AM
09 Dec @ 04:00AM
09 Dec @ 05:28AM
09 Dec @ 05:14PM
12 Dec @ 07:48PM
12 Dec @ 07:50PM
13 Dec @ 05:02AM
13 Dec @ 05:24AM
13 Dec @ 03:43PM
21 Dec @ 09:40AM
21 Dec @ 03:56PM