Skip to content

Instantly share code, notes, and snippets.

@amka
Created April 8, 2016 09:41
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 amka/7f01957f433a854d6f6c4c60ea563af8 to your computer and use it in GitHub Desktop.
Save amka/7f01957f433a854d6f6c4c60ea563af8 to your computer and use it in GitHub Desktop.
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