Skip to content

Instantly share code, notes, and snippets.

@munro
Last active January 21, 2016 04:35
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 munro/dbda79e245a469e7fe6a to your computer and use it in GitHub Desktop.
Save munro/dbda79e245a469e7fe6a to your computer and use it in GitHub Desktop.
from itertools import imap, ifilter, islice, count
def xf(v):
mapped = imap(lambda x: x * 2, v)
return ifilter(lambda x: x % 3 == 0, mapped)
print(list(islice(xf(count()), 10)))
def partition_all(size, items):
buf = []
for item in items:
buf.append(item)
if len(buf) == size:
yield buf
buf = []
if buf:
yield buf
print(list(partition_all(3, range(50))))
print(list(islice(partition_all(3, count()), 5)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment