Created
May 1, 2018 19:08
-
-
Save Perlence/5b7c6ecb400fc6e2cb376b74d3a89622 to your computer and use it in GitHub Desktop.
Decision table generator
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 csv | |
import itertools | |
import sys | |
def main(): | |
reader = csv.reader(sys.stdin, delimiter='\t') | |
conditions = {} # ordered dict is assumed | |
for line in reader: | |
if not line: | |
continue | |
condition, *values = line | |
conditions[condition] = values | |
possible_combinations = itertools.product(*conditions.values()) | |
transposed = zip(*possible_combinations) | |
writer = csv.writer(sys.stdout, delimiter='\t') | |
for condition, values in zip(conditions, transposed): | |
writer.writerow((condition, *values)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment