Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Python List Manipulation

By: a guest on Aug 22nd, 2012  |  syntax: Python  |  size: 2.55 KB  |  hits: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. DEMO_LIST = [[{'unweighted_criket_data': [-46.14554728131345, 2.997789122813151, -23.66171024766996]}, {'weighted_criket_index_input': [-6.275794430258629, 0.4076993207025885, -3.2179925936831144]}, {'manual_weighted_cricket_data': [-11.536386820328362, 0.7494472807032877, -5.91542756191749]},
  2.                 {'average_weighted_cricket_data': [-8.906090625293496, 0.5785733007029381, -4.566710077800302]}], [{'unweighted_football_data': [-7.586729834820534, 3.9521665714843675, 5.702038461085529]}, {'weighted_football_data': [-3.512655913521907, 1.8298531225972623, 2.6400438074826]}, {'manual_weighted_football_data': [-1.8966824587051334, 0.9880416428710919, 1.4255096152713822]},
  3.                 {'average_weighted_football_data': [-2.70466918611352, 1.4089473827341772, 2.0327767113769912]}], [{'unweighted_rugby_data': [199.99999999999915, 53.91020408163265, -199.9999999999995]}, {'weighted_rugby_data': [3.3999999999999857, 0.9164734693877551, -3.3999999999999915]}, {'manual_rugby_data': [49.99999999999979, 13.477551020408162, -49.99999999999987]}, {'average_weighted_rugby_data': [26.699999999999886, 7.197012244897959, -26.699999999999932]}], [{'unweighted_swimming_data': [2.1979283454982053, 14.079951031527246, -2.7585499298828777]}, {'weighted_swimming_data': [0.8462024130168091, 5.42078114713799, -1.062041723004908]}, {'manual_weighted_swimming_data': [0.5494820863745513, 3.5199877578818115, -0.6896374824707194]}, {'average_weighted_swimming_data': [0.6978422496956802, 4.470384452509901, -0.8758396027378137]}]]
  4.  
  5. def output(data_list):
  6.         result_u1 = 0
  7.         result_u2 = 0
  8.         result_u3 = 0
  9.         result_w1 = 0
  10.         result_w2 = 0
  11.         result_w3 = 0
  12.         result_a1 = 0
  13.         result_a2 = 0
  14.         result_a3 = 0
  15.         result_m1 = 0
  16.         result_m2 = 0
  17.         result_m3 = 0
  18.                
  19.         for i in range(0, len(data_list)-1):
  20.                 result_u1+=data_list[i][0].values()[0][0]
  21.                 result_u2+=data_list[i][0].values()[0][1]
  22.                 result_u3+=data_list[i][0].values()[0][2]
  23.                
  24.                 result_w1+=data_list[i][1].values()[0][0]
  25.                 result_w2+=data_list[i][1].values()[0][1]
  26.                 result_w3+=data_list[i][1].values()[0][2]
  27.                
  28.                 result_m1+=data_list[i][2].values()[0][0]
  29.                 result_m2+=data_list[i][2].values()[0][1]
  30.                 result_m3+=data_list[i][2].values()[0][2]
  31.                
  32.                 result_a1+=data_list[i][3].values()[0][0]
  33.                 result_a2+=data_list[i][3].values()[0][1]
  34.                 result_a3+=data_list[i][3].values()[0][2]
  35.                
  36.         print "UNWEIGHTED ",result_u1/4,result_u2/4,result_u3/4
  37.        
  38.         print "WEIGHTED", result_w1,result_w2,result_w3
  39.        
  40.         print "MANUAL WEIGHTED", result_m1,result_m2,result_m3
  41.        
  42.         print "AVERAGE WEIGHTED", result_a1,result_a2,result_a3
  43.  
  44. if __name__ == '__main__':
  45.         output(DEMO_LIST)