Created
April 8, 2016 09:41
-
-
Save amka/7f01957f433a854d6f6c4c60ea563af8 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 process_chunk(*items): | |
pass | |
def process_count(count): | |
print 'Count %d' % count | |
def chunked(iters, size): | |
n = 0 | |
l = [] | |
for item in iters: | |
l.append(item) | |
n += 1 | |
if n == size: | |
yield l | |
l = [] | |
n = 0 | |
if l: | |
yield l | |
def main(items): | |
"""Process and Count | |
>>> items = xrange(101) | |
>>> main(items=items) | |
Count 101 | |
>>> items = xrange(100) | |
>>> main(items=items) | |
Count 100 | |
:param items: | |
:return: | |
""" | |
total = 0 | |
for chunk in chunked(iters=items, size=10): | |
process_chunk(*chunk) | |
total += len(chunk) | |
process_count(total) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment