SHARE
TWEET

Untitled

a guest May 26th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. all_dates = ['1/2/18','1/3/18','15/2/18']
  2. patterns = ['%d/%m/%y', '%m/%d/%y']  
  3. for p in patterns:
  4.         pattern_counter = 0
  5.         fail_counter = 0
  6.         for s in all_dates:
  7.             try:
  8.                 conv = datetime.strptime(s, p)
  9.                 formatted = conv.strftime(p)
  10.                 pattern_counter += 1
  11.             except ValueError:
  12.                
  13.                 fail_counter +=1
  14.         print('fail counter', fail_counter, ' pattern_counter ', pattern_counter)
  15.         if pattern_counter > fail_counter:
  16.             print(p)
  17. output:
  18. fail counter 0  pattern_counter  3
  19. %d/%m/%y
  20. fail counter 1  pattern_counter  2
  21. %m/%d/%y
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top