Skip to content

Instantly share code, notes, and snippets.

@Perlence
Created May 1, 2018 19:08
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 Perlence/5b7c6ecb400fc6e2cb376b74d3a89622 to your computer and use it in GitHub Desktop.
Save Perlence/5b7c6ecb400fc6e2cb376b74d3a89622 to your computer and use it in GitHub Desktop.
Decision table generator
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