Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #RB = Running Back
- #OL = Outside Linebacker
- #WR = Wide Receiver
- #TE = Tight End
- #FB = Full Back
- #DB = Defensive Back
- #QB = Quarter Back
- #LB = Linebacker
- #DL = Defensive Lineman
- def middle(L):
- L = sorted(L)
- n = len(L)
- m = n - 1
- return (L[n/2] + L[m/2]) / 2.0
- def main():
- masterDict = {} # will only be added to, not reset
- #with open('tester.txt') as f:
- with open('DataSet_DEADNFLPLAYERS.txt') as f:
- for line in f:
- current_line = line.split(',')
- #print current_line
- masterDict.update({len(masterDict) : current_line})
- #print masterDict
- total_lifeSpan = 0
- listAges = []
- for key, value in masterDict.items():
- if(key != 0):
- deathYear = int(float(value[10].strip())) #10th element
- birthYear = int(float(value[len(value)-1].strip())) #last element
- age = deathYear - birthYear # determines the age at death
- listAges.append(age) # adds age to a list
- total_lifeSpan = total_lifeSpan + age # the combinded age of all players at death
- #-------------------------------------------------------------------------
- #mean, average age across all players
- print "MEAN"
- average_age = total_lifeSpan / (len(masterDict) -1)
- print average_age
- print "----------"
- #mode, the most commonly occuring value
- print "MODE"
- from collections import Counter
- data = Counter(listAges)
- print data.most_common(1)
- print "----------"
- #median, the least extreme value or the middle value
- print "MEDIAN"
- print middle(listAges)
- print "----------"
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement