Created
November 1, 2013 14:22
-
-
Save yao2030/7266153 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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] ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tom 4 | |
peter 3 | |
tom 3 | |
jack 5 | |
peter 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{'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