楼主:
Neisseria (Neisseria)
2015-04-16 14:49:22参考看看
num = {} # for how many times a key appears
seq = {} # for when a key appears
output = []
with open('file1.txt') as f:
for line in f:
k = line.strip()
if not k in num:
num[k] = 1
seq[k] = len(num)
else:
num[k] += 1
output.append(str(seq[k]) + '.' + str(num[k]))
print output # or rearrange and re-direct to file
※ 引述《Dong0129 (阿东)》之铭言:
: file1: file2:
: asia 1.1
: asia 1.2
: usa 2.1
: usa 2.2
: asia 1.3
: eup 3.1
: usa 2.3
: eup 3.2
: . .
: . .
: . .
: 各位版友好,
: 假设File1里有多笔资料,
: 请问有没有办法可以将File1的资料转换如File2呢?
: 麻烦各位了...