Advertisement
g3x0

Untitled

Sep 15th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import re
  2.  
  3. I = open('c.txt', 'r')
  4. I = I.readlines()
  5. O = open('z.txt', 'w')
  6. counties = 'AB|CV|GJ|IF|OT|SV|VS|AR|CL|DB|HR|MM|PH|TR|VN|AG|CS|DJ|HD|MH|SJ|TM|CJ|GL|IL|MS|SM|TL|B|CT|GR|IS|NT|SB|VL'
  7. dic = ['O', 'I', 'Z', 'E', 'A', 'S', 'G', 'T', 'B', 'Q']
  8. words = []
  9.  
  10. for word in I:
  11. word = word.replace('\r\n', '')
  12.  
  13. if ((len(word) == 6 and word[0] == 'B') or len(word) == 7) and re.search('^(' + counties + ')', word):
  14. if word[0] == 'B':
  15. if len(word) == 7 and word[3] in dic:
  16. if word[1] in dic and word[2] in dic and word[3] in dic:
  17. word = 'B ' + str(dic.index(word[1])) + str(dic.index(word[2])) + str(dic.index(word[3])) + ' ' + word[4:]
  18. words.append(word)
  19.  
  20. if len(word) == 6:
  21. if word[1] in dic and word[2] in dic:
  22. word = 'B ' + str(dic.index(word[1])) + str(dic.index(word[2])) + ' ' + word[3:]
  23. words.append(word)
  24. else:
  25. if word[2] in dic and word[3] in dic:
  26. word = word[:2] + ' ' + str(dic.index(word[2])) + str(dic.index(word[3])) + ' ' + word[4:]
  27. words.append(word)
  28.  
  29. O.write('\r\n'.join(words))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement