作者:
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呢?
: 麻煩各位了...