Skip to content

Instantly share code, notes, and snippets.

@miku
Created December 14, 2020 22:17
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 miku/a221c0bdf10828869a3a37f97904f8e4 to your computer and use it in GitHub Desktop.
Save miku/a221c0bdf10828869a3a37f97904f8e4 to your computer and use it in GitHub Desktop.
Generate combinations from a list
#!/usr/bin/env python
"""
Turn:
a
b
c
into:
a,b
a,c
b,c
"""
import fileinput
import itertools
vs = set()
for line in fileinput.input():
line = line.strip()
if not line:
continue
vs.add(line)
for a, b in itertools.combinations(sorted(vs), r=2):
print("{}\t{}".format(a, b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment