Skip to content

Instantly share code, notes, and snippets.

@stillinbeta
Created November 9, 2014 17:42
Show Gist options
  • Save stillinbeta/0c5b5bf23c5d808c8d02 to your computer and use it in GitHub Desktop.
Save stillinbeta/0c5b5bf23c5d808c8d02 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
def stats(f):
nums = []
for i, line in enumerate(f):
nums.append(int(line.strip()))
if i % 5 == 0:
yield (sum(nums), min(nums), max(nums))
nums = []
if __name__ == "__main__":
with open('/tmp/numbers.txt') as f:
for sum_, min_, max_ in stats(f):
print("sum {}, min {}, max{}".format(sum_, min_, max_))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment