summn1.py 570 Bytes
Newer Older
Loïc Barrault's avatar
Loïc Barrault committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

import sys, re
f = open(sys.argv[1],'r')

def countWords(line):
    return len(re.findall('[a-z]+',line.lower()))

lines = []
totalwords = 0
for line in f:
    lines.append(line)
    totalwords += countWords(line)
    print '[%d]' % countWords(line), line,
f.close()

print 'Total Words:', totalwords
sum_limit = int (totalwords * (float(sys.argv[2]) / 100))
print 'Summ Limit:', sum_limit

print '-' * 55
sum_len = 0
for line in lines:
    c = countWords(line)
    if sum_len + c > sum_limit:
        break
    print line,
    sum_len += c
print 'Sum-Len:', sum_len