The python script generates all combinations of sentences from the list of words in a brute force, but not non-repeated words in each line (sentence). How to alter the code to give all the possible combinations, including repeating words (for a given number of words)?
#!/usr/bin/env python3 from itertools import permutations from argparse import ArgumentParser, ArgumentError parser = ArgumentParser( description='Print all possible permutations of strings from a file' ) parser.add_argument( '-f', '--file', help='file to read strings from' ) parser.add_argument( '-min', '--minimum', help='minimal number of words in a single sentence' ) parser.add_argument( '-max', '--maximum', help='maximal number of words in a single sentence' ) if __name__ == '__main__': args = parser.parse_args() if not args.file: raise ArgumentError(args.file, C) with open(args.file) as f: strings = tuple(filter(None, f.read().splitlines())) minimum = int(args.minimum) or 1 maximum = int(args.maximum) or len(strings) for length in range(minimum, maximum+1): for sentence in permutations(strings, length): print(' '.join(sentence))
minimum = int(args.minimum) or 1? And the next line. - Enikeyschikpython3 script.py -f spisokslov.txt -min 1 -max 8- TWOfish