Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- I = open('c.txt', 'r')
- I = I.readlines()
- O = open('z.txt', 'w')
- 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'
- dic = ['O', 'I', 'Z', 'E', 'A', 'S', 'G', 'T', 'B', 'Q']
- words = []
- for word in I:
- word = word.replace('\r\n', '')
- if ((len(word) == 6 and word[0] == 'B') or len(word) == 7) and re.search('^(' + counties + ')', word):
- if word[0] == 'B':
- if len(word) == 7 and word[3] in dic:
- if word[1] in dic and word[2] in dic and word[3] in dic:
- word = 'B ' + str(dic.index(word[1])) + str(dic.index(word[2])) + str(dic.index(word[3])) + ' ' + word[4:]
- words.append(word)
- if len(word) == 6:
- if word[1] in dic and word[2] in dic:
- word = 'B ' + str(dic.index(word[1])) + str(dic.index(word[2])) + ' ' + word[3:]
- words.append(word)
- else:
- if word[2] in dic and word[3] in dic:
- word = word[:2] + ' ' + str(dic.index(word[2])) + str(dic.index(word[3])) + ' ' + word[4:]
- words.append(word)
- O.write('\r\n'.join(words))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement