Advertisement
asweigart

alphabetical order checking script

Mar 11th, 2018
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import pyperclip, time, sys, re
  2.  
  3. # Every second, checks to make sure the contents of the clipboard are in
  4. # alphabetical order. I'm using this to check if the index I'm writing is in
  5. # alphabetical order, which is tricky since it has sub-entries which are out
  6. # of order relative to the main entries.
  7.  
  8. while True:
  9. entries = [x.strip().lower() for x in pyperclip.paste().split('\n') if x.strip() != '']
  10. entries = [re.sub('[^a-z ]', '', x) for x in entries] # remove non-letter
  11. sortedEntries = sorted(entries)
  12.  
  13. if entries == sortedEntries:
  14. print('Ok')
  15. else:
  16. print('Out of order:\n', '\n'.join(entries))
  17. print()
  18. print('Should be:\n', '\n'.join(sortedEntries))
  19. sys.exit()
  20. time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement