Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 25th, 2012  |  syntax: None  |  size: 1.14 KB  |  views: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import codecs
  2.  
  3. with codecs.open('text.txt', "r", "utf-8-sig") as handle:
  4.     numbers = []
  5.     count = []
  6.  
  7.     for i in range(24):
  8.        numbers.append(float(0))
  9.  
  10.     for i in range(24):
  11.        count.append(float(0))
  12.  
  13.     for line in handle:
  14.  
  15.         lineSplit = line.split()
  16.        
  17.         fieldOne = lineSplit[0]
  18.         numOne = fieldOne.split('.')[0]
  19.  
  20.         fieldTwo = lineSplit[len(lineSplit)-1]
  21.         numTwo = fieldTwo.split('/')[0]
  22.  
  23.         numOne = int(numOne)
  24.         numTwo = float(numTwo)
  25.  
  26.         count[numOne-1] = count[numOne-1] + 1
  27.        
  28.         numbers[numOne-1] = numbers[numOne-1] + numTwo
  29.  
  30.     for i in range(24):
  31.         numbers[i] = numbers[i]/count[i]
  32.         print str(i+1) + ": " + str(numbers[i])
  33.  
  34.  
  35. Results:
  36.  
  37. 1: 7.76923076923
  38. 2: 7.99545454545
  39. 3: 8.17916666667
  40. 4: 8.27727272727
  41. 5: 8.35
  42. 6: 8.38
  43. 7: 8.336
  44. 8: 8.216
  45. 9: 7.904
  46. 10: 7.65652173913
  47. 11: 7.39090909091
  48. 12: 7.42380952381
  49. 13: 7.15909090909
  50. 14: 7.03636363636
  51. 15: 7.05454545455
  52. 16: 7.13333333333
  53. 17: 7.03636363636
  54. 18: 7.20454545455
  55. 19: 7.095
  56. 20: 7.01904761905
  57. 21: 7.02173913043
  58. 22: 6.99090909091
  59. 23: 7.04545454545
  60. 24: 7.0375