Created
December 23, 2012 18:16
-
-
Save kbob/4365004 to your computer and use it in GitHub Desktop.
Iterate combinations of an infinite set
This file contains hidden or 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
import itertools | |
def infinite_combinations(n, iterator): | |
seen = [] | |
for item in iterator: | |
for subset in itertools.combinations(seen, n - 1): | |
yield subset + (item,) | |
seen.append(item) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment