Created
December 14, 2020 22:17
-
-
Save miku/a221c0bdf10828869a3a37f97904f8e4 to your computer and use it in GitHub Desktop.
Generate combinations from a list
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
#!/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