Skip to content

Instantly share code, notes, and snippets.

@tnarihi
Last active August 28, 2015 06:46
Show Gist options
  • Save tnarihi/03f45d9591756c9f4a34 to your computer and use it in GitHub Desktop.
Save tnarihi/03f45d9591756c9f4a34 to your computer and use it in GitHub Desktop.
from __future__ import print_function
import argparse
import random
parser = argparse.ArgumentParser()
parser.add_argument('text_input', help='Path to input file')
parser.add_argument('--seed', type=int, default=313,
help='Seed of random')
parser.add_argument('--stack', type=int, default=9,
help='Number of stack (default: 9)'),
args = parser.parse_args()
with open(args.text_input, 'r') as fd:
s = 0
slines = []
while True:
lines = []
for i in xrange(args.stack):
line = fd.readline()
if line == '':
break
lines += [line]
if len(lines) == 0:
break
elif len(lines) == args.stack:
slines += [lines]
else:
raise ValueError(
"The text must have number of lines"
"with multiple of stack={}".format(args.stack))
random.seed(args.seed)
random.shuffle(slines)
for lines in slines:
for line in lines:
print(line, end='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment