Last active
June 15, 2018 02:32
-
-
Save comynli/233412cd89bf671d7f9d754a3137be4f to your computer and use it in GitHub Desktop.
This file contains 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
def two(path): | |
tmp = {} | |
with open(path) as f: | |
for line in f: | |
k, v = line.split(',') | |
k = k.strip() | |
v = float(v) | |
s, c = tmp.get(k, (0, 0)) | |
tmp[k] = (s+v, c+1) | |
for k, (s, c) in tmp.items(): | |
yield k, s, s/c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment