我有一个文件,我必须做两件事。首先计算一个特定的模式,如果计数超过 5,我必须打印所有包含的行。
输入文件:
0- 0: 2257042_7 2930711_14
0- 1: 2257042_8 2930711_13
0- 2: 2257042_9 2930711_12
0- 3: 2257042_10 2930711_11
0- 4: 2257042_11 2930711_10
0- 5: 2257042_13 2930711_8
0- 6: 2257042_14 2930711_7
0- 7: 2257042_15 2930711_6
0- 8: 2257042_16 2930711_5
1- 0: 2258476_3 2994500_2
1- 1: 2258476_4 2994500_3
1- 2: 2258476_5 2994500_4
1- 3: 2258476_6 2994500_5
1- 4: 2258476_7 2994500_6
2- 0: 2259527_1 2921847_10
2- 1: 2259527_2 2921847_9
2- 2: 2259527_3 2921847_8
2- 3: 2259527_4 2921847_7
2- 4: 2259527_5 2921847_6
2- 5: 2259527_6 2921847_5
38- 0: 2323304_2 3043768_5
38- 1: 2323304_3 3043768_6
38- 2: 2323304_4 3043768_7
38- 3: 2323304_5 3043768_8
38- 4: 2323304_6 3043768_9
38- 5: 2323304_7 3043768_10
38- 6: 2323304_8 3043768_11
39- 0: 2323953_1 3045012_9
39- 1: 2323953_2 3045012_8
39- 2: 2323953_3 3045012_7
39- 3: 2323953_4 3045012_6
39- 4: 2323953_7 3045012_3
39- 5: 2323953_8 3045012_2
40- 0: 2331568_2 3042876_8
40- 1: 2331568_3 3042876_7
40- 2: 2331568_4 3042876_6
40- 3: 2331568_5 3042876_5
40- 4: 2331568_6 3042876_4
40- 5: 2331568_9 3042876_2
40- 6: 2331568_10 3042876_1
预期输出:
0- 0: 2257042_7 2930711_14
0- 1: 2257042_8 2930711_13
0- 2: 2257042_9 2930711_12
0- 3: 2257042_10 2930711_11
0- 4: 2257042_11 2930711_10
0- 5: 2257042_13 2930711_8
0- 6: 2257042_14 2930711_7
0- 7: 2257042_15 2930711_6
0- 8: 2257042_16 2930711_5
38- 0: 2323304_2 3043768_5
38- 1: 2323304_3 3043768_6
38- 2: 2323304_4 3043768_7
38- 3: 2323304_5 3043768_8
38- 4: 2323304_6 3043768_9
38- 5: 2323304_7 3043768_10
38- 6: 2323304_8 3043768_11
40- 0: 2331568_2 3042876_8
40- 1: 2331568_3 3042876_7
40- 2: 2331568_4 3042876_6
40- 3: 2331568_5 3042876_5
40- 4: 2331568_6 3042876_4
40- 5: 2331568_9 3042876_2
40- 6: 2331568_10 3042876_1
所以为此我把我不知道的编码放在这里是错误的。我没有得到预期的输出。编码:
import sys
coll_file = open (sys.argv[1]).readlines()
old_pattern = ''
for lines in coll_file:
pattern_count = 0
split_line = lines.split('\t')
pattern = split_line[0]
if pattern == old_pattern:
pattern_count = pattern_count+1
if pattern_count > '5':
print lines.strip()
old_pattern = pattern