以下file.txt
では、表示されているIDごとに、IDの通貨が検出された回数を確認する必要があります。これどうやってするの?
file.txt
ID101\tbill is $200
ID101\tyour bill
ID101\t $200 again
ID101\t$100 is the generated amount
ID101\t$50 is your amount
ID101\t$74 is the amount
ID102\tNo bill
ID102\tbill is $75
ID103\t$65 is your bill
ID103\tno bill
コード
f=open("file.txt")
arr=[]
count = 0
for l in f:
col = 0
for i in l.split("\t"):
if col == 0:
if i not in arr: //tocheck whether it is a new id or not
arr.append(i)
if col == 1:
if "$" in i:
count += 1
col += 1
各IDのカウントを確認するにはどうすればよいですか?