Created
November 9, 2014 17:42
-
-
Save stillinbeta/0c5b5bf23c5d808c8d02 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
#!/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