Created
April 7, 2014 14:09
-
-
Save Chovanec/10020978 to your computer and use it in GitHub Desktop.
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
# 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