
Untitled
By: a guest on
Dec 25th, 2012 | syntax:
None | size: 1.14 KB | hits: 21 | expires: Never
import codecs
with codecs.open('text.txt', "r", "utf-8-sig") as handle:
numbers = []
count = []
for i in range(24):
numbers.append(float(0))
for i in range(24):
count.append(float(0))
for line in handle:
lineSplit = line.split()
fieldOne = lineSplit[0]
numOne = fieldOne.split('.')[0]
fieldTwo = lineSplit[len(lineSplit)-1]
numTwo = fieldTwo.split('/')[0]
numOne = int(numOne)
numTwo = float(numTwo)
count[numOne-1] = count[numOne-1] + 1
numbers[numOne-1] = numbers[numOne-1] + numTwo
for i in range(24):
numbers[i] = numbers[i]/count[i]
print str(i+1) + ": " + str(numbers[i])
Results:
1: 7.76923076923
2: 7.99545454545
3: 8.17916666667
4: 8.27727272727
5: 8.35
6: 8.38
7: 8.336
8: 8.216
9: 7.904
10: 7.65652173913
11: 7.39090909091
12: 7.42380952381
13: 7.15909090909
14: 7.03636363636
15: 7.05454545455
16: 7.13333333333
17: 7.03636363636
18: 7.20454545455
19: 7.095
20: 7.01904761905
21: 7.02173913043
22: 6.99090909091
23: 7.04545454545
24: 7.0375