-
-
Save munro/dbda79e245a469e7fe6a 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
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