Skip to content

Instantly share code, notes, and snippets.

@kbob
Created December 23, 2012 18:16
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 kbob/4365004 to your computer and use it in GitHub Desktop.
Save kbob/4365004 to your computer and use it in GitHub Desktop.
Iterate combinations of an infinite set
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