在下面file.txt
显示的每个 ID 中,我需要检查为一个 ID 找到货币的次数。我怎样才能做到这一点?
文件.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 的计数?