python或shell怎么计算重复次数的有关问题

python或shell如何计算重复次数的问题
本帖最后由 silverpearlx 于 2014-04-22 17:46:04 编辑
文本内容如下:
===================
0
0
590.09
0
0
1045.17
2251.11
1469.52
0
0
0
0
4396.94
0
0
4799.82
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
===================
请教如何才能统计出连续0值出现的次数.理论应该输出这样的结果:
2
2
4
2
16

------解决方案--------------------
f = open('your data file')
count = 0
for line in f:
    if not float(line):
        count += 1
    elif count:
        print count
        count = 0
if count:
    print count
f.close()