Skip to content

Instantly share code, notes, and snippets.

@yao2030
Created November 1, 2013 14:22
Show Gist options
  • Save yao2030/7266153 to your computer and use it in GitHub Desktop.
Save yao2030/7266153 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/python2.7
grad = {}
stu = {}
with open("input.txt") as f:
for l in f:
name, score = l.strip().split()
if name not in grad:
grad[name] = 0
if name not in stu:
stu[name] = 0
grad[name] += int(score)
stu[name] += 1
print grad
print stu
for x in stu:
print x + " " + str( float(grad[x])/stu[x] )
tom 4
peter 3
tom 3
jack 5
peter 3
{'peter': 6, 'jack': 5, 'tom': 7}
{'peter': 2, 'jack': 1, 'tom': 2}
peter 3.0
jack 5.0
tom 3.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment