|
发表于 2019-12-26 22:34:25
|
显示全部楼层
本帖最后由 hrp 于 2019-12-26 22:56 编辑
- with open('A.txt', 'rt', encoding='utf-8') as A:
- Alines = A.readlines()
- A.close()
- listA = []
- for i1 in Alines:
- i1 = i1.strip().split(' ')
- i2 = i1[-1].split('-')
- listA.append(
- (i1[0], int(i2[0]), int(i2[1]))
- )
- #print(listA)
- with open('B.txt', 'rt', encoding='utf-8') as B:
- Blines = B.readlines()
- B.close()
- listB = []
- for i in range(0, len(Blines), 2):
- listB.append(
- (Blines[i].strip(), Blines[i+1].strip())
- )
- #print(listB)
- for i in listA:
- for j in listB:
- if j[0][1:] == i[0]:
- print(j[0], '\t', str(i[1])+'-'+str(i[2]))
- print(j[1][i[1]-1:i[2]])
复制代码 |
|