coding utf8 leftPart rightPart result with open input txt as leftPart

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding:utf8 -*-
leftPart = ""
rightPart = ""
result = []
with open("input.txt", "r") as f:
leftPart, rightPart = f.readline().split("::=")
f.close()
def gramma(string):
i = 0
while i < len(string):
if (string[i].isdigit() or string[i].islower()):
t = string[i]
i += 1
for j in string[i:]:
if j.isdigit() or string[i].islower():
t += j
i += 1
else:
break
result.append("<{0}, {1}>".format(0, t))
else:
result.append("<{0}, {1}>".format(1, string[i]))
i += 1
if __name__ == '__main__':
gramma(leftPart)
gramma(rightPart)
for i in result:
print i