Skip to content

Instantly share code, notes, and snippets.

@Chovanec
Created April 7, 2014 14:09
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 Chovanec/10020978 to your computer and use it in GitHub Desktop.
Save Chovanec/10020978 to your computer and use it in GitHub Desktop.
# script in python 3.3
import sys
import pprint
def vd (input):
pprint.pprint (input)
try:
file = open('input.txt', 'r')
file = file.read()
except:
input("\"input.txt\" file do not exist")
sys.exit()
# remove new lines
file = file.replace('\n', '')
# split to list/array
file = file.split("|no")
# remove "" empty items
file = list(filter(None, file))
# remove numbers (n:)
blocks = []
for item in file:
_numb, _sep, line = item.partition(':')
blocks.append(line)
# lines split (|)
temp = blocks
blocks = []
for item in temp:
lines = item.split('|')
blocks.append(lines)
# all sentences split (,)
temp = blocks
blocks = []
sentences = []
for block in temp:
_block = []
for line in block:
_sentences = []
_start, _, _last = line.rpartition(' ')
for item in _last.split(','):
_sentences.append(_start + ' ' + item)
_block.append(_sentences)
blocks.append(_block)
############################################
output = ''
num = 0
for block in blocks:
output = output + str(num) + ':'
for sentences in block:
for sentence in sentences:
output = output + sentence + '|'
output = output + 'no\n'
num = num + 1
############################################
############################################
from itertools import product
output = ''
num = 0
for block in blocks:
combinations = list(product(*block))
for comb in combinations:
comb = list(comb)
output = output + str(num) + ':' + '|'.join(comb) + '|no\n'
num = num + 1
f = open('output.txt', 'w')
f.write(output)
f.close()
############################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment