Skip to content

Instantly share code, notes, and snippets.

@comynli
Last active June 15, 2018 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save comynli/233412cd89bf671d7f9d754a3137be4f to your computer and use it in GitHub Desktop.
Save comynli/233412cd89bf671d7f9d754a3137be4f to your computer and use it in GitHub Desktop.
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